Skip to content

Commit 4d0589e

Browse files
committed
Cleanup
1 parent 3b7c837 commit 4d0589e

File tree

3 files changed

+16
-41
lines changed

3 files changed

+16
-41
lines changed

src/Service/CodeValidator/HtmlPhpValidator.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/Service/CodeValidator/PhpValidator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ class PhpValidator implements Validator
1717
public function validate(CodeNode $node, IssueCollection $issues): void
1818
{
1919
$language = $node->getLanguage() ?? ($node->isRaw() ? null : 'php');
20-
if (!in_array($language, ['php', 'php-symfony', 'php-standalone', 'php-annotations'])) {
20+
if (!in_array($language, ['php', 'php-symfony', 'php-standalone', 'php-annotations', 'html+php'])) {
2121
return;
2222
}
2323

24-
$parser = $this->getParser();
25-
$errorHandler = new ErrorHandler\Collecting();
24+
$linesPrepended = 0;
25+
$code = 'html+php' === $language ? $node->getValue() : $this->getContents($node, $linesPrepended);
26+
$this->getParser()->parse($code, $errorHandler = new ErrorHandler\Collecting());
2627

27-
$parser->parse($this->getContents($node, $linesPrepended), $errorHandler);
2828
foreach ($errorHandler->getErrors() as $error) {
2929
$issues->addIssue(new Issue($node, $error->getRawMessage(), 'PHP syntax', $node->getEnvironment()->getCurrentFileName(), $error->getStartLine() - $linesPrepended));
3030
}

tests/Service/Validator/PhpValidatorTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\RST\Nodes\CodeNode;
88
use PHPUnit\Framework\TestCase;
99
use SymfonyTools\CodeBlockChecker\Issue\IssueCollection;
10+
use SymfonyTools\CodeBlockChecker\Service\CodeValidator\HtmlPhpValidator;
1011
use SymfonyTools\CodeBlockChecker\Service\CodeValidator\PhpValidator;
1112
use SymfonyTools\CodeBlockChecker\Service\CodeValidator\Validator;
1213

@@ -56,11 +57,11 @@ public function testLocalLine()
5657
/**
5758
* @dataProvider getCodeExamples
5859
*/
59-
public function testCodeExamples(int $errors, string $code)
60+
public function testCodeExamples(int $errors, string $code, ?string $language = null)
6061
{
6162
$node = new CodeNode(explode(PHP_EOL, $code));
6263
$node->setEnvironment($this->environment);
63-
$node->setLanguage('php');
64+
$node->setLanguage($language ?? 'php');
6465
$this->validator->validate($node, $issues = new IssueCollection());
6566
$this->assertCount($errors, $issues);
6667
}
@@ -107,5 +108,14 @@ public static function validate($object, ExecutionContextInterface $context, $pa
107108
$foo = 2a
108109
}
109110
'];
111+
yield [0, '
112+
<h1>Hello</h1>
113+
<p><? echo $value; ?></p>
114+
', 'html+php'];
115+
116+
yield [1, '
117+
<h1>Hello</h1>
118+
<p><?php value foobar ?></p>
119+
', 'html+php'];
110120
}
111121
}

0 commit comments

Comments
 (0)