-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PHPStan] Run PHPStan rich parser in tests to know the types + proces…
…s code with tolerant parses on 1st run (#1790)
- Loading branch information
1 parent
94ef798
commit e9fb346
Showing
4 changed files
with
61 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\PhpParser\Parser; | ||
|
||
use PhpParser\Node\Stmt; | ||
use PHPStan\File\FileHelper; | ||
use PHPStan\Parser\Parser; | ||
use PHPStan\Parser\PathRoutingParser; | ||
|
||
/** | ||
* @api Used in PHPStan internals for parsing nodes: | ||
* 1) with types for tests: | ||
* 2) removing unsupported PHP-version code on real run | ||
*/ | ||
final class RectorPathRoutingParser extends PathRoutingParser | ||
{ | ||
private readonly Parser $currentPhpVersionRichParser; | ||
|
||
public function __construct( | ||
FileHelper $fileHelper, | ||
Parser $currentPhpVersionRichParser, | ||
Parser $currentPhpVersionSimpleParser, | ||
Parser $php8Parser | ||
) { | ||
$this->currentPhpVersionRichParser = $currentPhpVersionRichParser; | ||
parent::__construct($fileHelper, $currentPhpVersionRichParser, $currentPhpVersionSimpleParser, $php8Parser); | ||
} | ||
|
||
/** | ||
* @return Stmt[] | ||
*/ | ||
public function parseFile(string $file): array | ||
{ | ||
// for tests, always parse nodes with directly rich parser to be aware of types | ||
if (defined('PHPUNIT_COMPOSER_INSTALL')) { | ||
return $this->currentPhpVersionRichParser->parseFile($file); | ||
} | ||
|
||
return parent::parseFile($file); | ||
} | ||
} |