File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 2222use PhpParser \Node \Stmt \UseUse ;
2323use PhpParser \NodeFinder ;
2424use PhpParser \ParserFactory ;
25- use PhpParser \PhpVersion ;
2625use PHPUnit \Framework \Assert ;
26+ use ReflectionClass ;
2727
2828use function array_pop ;
2929use function explode ;
@@ -40,9 +40,14 @@ final class GeneratedClassAsserter
4040 public function __construct (InMemoryFileWriter $ fileWriter , string $ path )
4141 {
4242 $ this ->nodeFinder = new NodeFinder ();
43- $ phpParser = (new ParserFactory ())->createForVersion (PhpVersion::fromString ('7.0 ' ));
44- $ phpCode = $ fileWriter ->getContentsByFullPath ($ path );
45- $ statements = $ phpParser ->parse ($ phpCode );
43+ if ((new ReflectionClass (ParserFactory::class))->hasMethod ('create ' )) {
44+ $ phpParser = (new ParserFactory ())->create (1 );
45+ } else {
46+ $ phpParser = (new ParserFactory ())->createForHostVersion ();
47+ }
48+
49+ $ phpCode = $ fileWriter ->getContentsByFullPath ($ path );
50+ $ statements = $ phpParser ->parse ($ phpCode );
4651 if ($ statements === null ) {
4752 throw new InvalidArgumentException ('No statements found in provided PHP code ' );
4853 }
You can’t perform that action at this time.
0 commit comments