Skip to content

Commit c37f8a6

Browse files
committed
CodeExistsCheck handle 7.2/7.3 parsing
1 parent 277aa99 commit c37f8a6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Check/CodeExistsCheck.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use PhpParser\Error;
88
use PhpParser\ErrorHandler;
9+
use PhpParser\Node\Stmt\InlineHTML;
10+
use PhpParser\NodeFinder;
911
use PhpParser\Parser;
1012
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
1113
use PhpSchool\PhpWorkshop\Exercise\ExerciseType;
@@ -46,7 +48,14 @@ public function handleError(Error $error): void
4648
$code = (string) file_get_contents($input->getRequiredArgument('program'));
4749
$statements = $this->parser->parse($code, $noopHandler);
4850

49-
if (null === $statements || empty($statements)) {
51+
$empty = null === $statements || empty($statements);
52+
53+
if (!$empty) {
54+
$openingTag = is_array($statements) && count($statements) === 1 ? $statements[0] : null;
55+
$empty = $openingTag instanceof InlineHTML ? in_array($openingTag->value, ['<?php', '<?']) : false;
56+
}
57+
58+
if ($empty) {
5059
return Failure::fromCheckAndReason($this, 'No code was found');
5160
}
5261

0 commit comments

Comments
 (0)