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 @@ -2050,7 +2050,11 @@ services:
2050
2050
autowired : false
2051
2051
2052
2052
currentPhpVersionPhpParser :
2053
- class : PhpParser\Parser\Php8 # todo use factory and create Php7/Php8
2053
+ factory : @currentPhpVersionPhpParserFactory::create ()
2054
+ autowired : false
2055
+
2056
+ currentPhpVersionPhpParserFactory :
2057
+ class : PHPStan\Parser\PhpParserFactory
2054
2058
arguments :
2055
2059
lexer : @currentPhpVersionLexer
2056
2060
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