File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 6
6
7
7
use PhpParser \Error ;
8
8
use PhpParser \ErrorHandler ;
9
+ use PhpParser \Node \Stmt \InlineHTML ;
10
+ use PhpParser \NodeFinder ;
9
11
use PhpParser \Parser ;
10
12
use PhpSchool \PhpWorkshop \Exercise \ExerciseInterface ;
11
13
use PhpSchool \PhpWorkshop \Exercise \ExerciseType ;
@@ -46,7 +48,14 @@ public function handleError(Error $error): void
46
48
$ code = (string ) file_get_contents ($ input ->getRequiredArgument ('program ' ));
47
49
$ statements = $ this ->parser ->parse ($ code , $ noopHandler );
48
50
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 ) {
50
59
return Failure::fromCheckAndReason ($ this , 'No code was found ' );
51
60
}
52
61
You can’t perform that action at this time.
0 commit comments