Skip to content

Commit

Permalink
Use non-emulative Lexer if the desired PHP version matches the runtim…
Browse files Browse the repository at this point in the history
…e one
  • Loading branch information
ondrejmirtes committed Jul 16, 2020
1 parent c1e8f6f commit 9f53ac5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ services:
class: PhpParser\BuilderFactory

-
class: PhpParser\Lexer\Emulative
class: PhpParser\Lexer
factory: @PHPStan\Parser\LexerFactory::create()

-
class: PHPStan\Parser\LexerFactory

-
class: PhpParser\NodeTraverser
Expand Down
27 changes: 27 additions & 0 deletions src/Parser/LexerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types = 1);

namespace PHPStan\Parser;

use PhpParser\Lexer;
use PHPStan\Php\PhpVersion;

class LexerFactory
{

private PhpVersion $phpVersion;

public function __construct(PhpVersion $phpVersion)
{
$this->phpVersion = $phpVersion;
}

public function create(): Lexer
{
if ($this->phpVersion->getVersionId() === PHP_VERSION_ID) {
return new Lexer();
}

return new Lexer\Emulative();
}

}
3 changes: 3 additions & 0 deletions src/Testing/TestCase-staticReflection.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
parameters:
phpVersion: 80000 # force Emulative lexer

services:
-
class: PHPStan\Testing\TestCaseSourceLocatorFactory
Expand Down

0 comments on commit 9f53ac5

Please sign in to comment.