File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -1864,7 +1864,11 @@ services:
1864
1864
autowired : false
1865
1865
1866
1866
currentPhpVersionPhpParser :
1867
- class : PhpParser\Parser\Php8 # todo use factory and create Php7/Php8
1867
+ factory : @currentPhpVersionPhpParserFactory::create ()
1868
+ autowired : false
1869
+
1870
+ currentPhpVersionPhpParserFactory :
1871
+ class : PHPStan\Parser\PhpParserFactory
1868
1872
arguments :
1869
1873
lexer : @currentPhpVersionLexer
1870
1874
autowired : false
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types = 1 );
2
+
3
+ namespace PHPStan \Parser ;
4
+
5
+ use PhpParser \Lexer ;
6
+ use PhpParser \Parser \Php7 ;
7
+ use PhpParser \Parser \Php8 ;
8
+ use PhpParser \ParserAbstract ;
9
+ use PHPStan \Php \PhpVersion ;
10
+
11
+ class PhpParserFactory
12
+ {
13
+
14
+ public function __construct (private Lexer $ lexer , private PhpVersion $ phpVersion )
15
+ {
16
+ }
17
+
18
+ public function create (): ParserAbstract
19
+ {
20
+ $ phpVersion = \PhpParser \PhpVersion::fromString ($ this ->phpVersion ->getVersionString ());
21
+ if ($ this ->phpVersion ->getVersionId () >= 80000 ) {
22
+ return new Php8 ($ this ->lexer , $ phpVersion );
23
+ }
24
+
25
+ return new Php7 ($ this ->lexer , $ phpVersion );
26
+ }
27
+
28
+ }
You can’t perform that action at this time.
0 commit comments