20
20
use PhpParser \NodeVisitor \NameResolver ;
21
21
use PhpParser \Parser ;
22
22
use PhpParser \Parser \Php7 ;
23
+ use PhpParser \ParserFactory ;
23
24
use PhpParser \PrettyPrinter \Standard ;
24
25
use RuntimeException ;
25
26
@@ -41,11 +42,6 @@ class CodeConverter
41
42
*/
42
43
protected $ parser ;
43
44
44
- /**
45
- * @var Lexer The PHP Lexer.
46
- */
47
- protected $ lexer ;
48
-
49
45
/**
50
46
* @var NodeTraverser The PHP Node Traverser.
51
47
*/
@@ -62,23 +58,19 @@ class CodeConverter
62
58
protected $ nodeFinder ;
63
59
64
60
/**
65
- * @param Lexer|null $lexer The PHP Lexer.
66
61
* @param Parser|null $parser The PHP Parser.
67
62
* @param NodeTraverser|null $traverser The PHP Node Traverser - make sure that the traverser has a CloningVisitor
68
63
* and a NameResolver visitor.
69
64
* @param Standard|null $printer The PHP Printer.
70
65
* @param NodeFinder|null $nodeFinder The PHP Node Finder.
71
66
*/
72
67
public function __construct (
73
- ?Lexer $ lexer = null ,
74
68
?Parser $ parser = null ,
75
69
?NodeTraverser $ traverser = null ,
76
70
?Standard $ printer = null ,
77
71
?NodeFinder $ nodeFinder = null
78
72
) {
79
- $ this ->lexer = $ lexer ?? $ this ->defaultLexer ();
80
-
81
- $ this ->parser = $ parser ?? new Php7 ($ this ->lexer );
73
+ $ this ->parser = $ parser ?? (new ParserFactory ())->createForNewestSupportedVersion ();
82
74
83
75
if ($ traverser === null ) {
84
76
$ traverser = new NodeTraverser ();
@@ -92,18 +84,6 @@ public function __construct(
92
84
$ this ->nodeFinder = $ nodeFinder ?? new NodeFinder ();
93
85
}
94
86
95
- /**
96
- * @return Lexer
97
- */
98
- private function defaultLexer (): Lexer
99
- {
100
- return new Emulative (
101
- [
102
- 'usedAttributes ' => ['comments ' , 'startLine ' , 'endLine ' , 'startTokenPos ' , 'endTokenPos ' ],
103
- ]
104
- );
105
- }
106
-
107
87
/**
108
88
* Convert the given source code.
109
89
*
@@ -119,7 +99,7 @@ public function convert(string $code, array $functionCallMap): string
119
99
throw new RuntimeException ('Code could not be parsed. ' );
120
100
}
121
101
122
- $ oldTokens = $ this ->lexer ->getTokens ();
102
+ $ oldTokens = $ this ->parser ->getTokens ();
123
103
124
104
$ newStmts = $ this ->traverser ->traverse ($ oldStmts );
125
105
0 commit comments