-
-
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.
add own RectorPathRoutingParser that handles test with rich parser by…
… default to let PHPStan know the types
- Loading branch information
1 parent
d9697ea
commit f364011
Showing
3 changed files
with
42 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\PhpParser\Parser; | ||
|
||
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 Parser $currentPhpVersionRichParser; | ||
|
||
public function __construct( | ||
\PHPStan\File\FileHelper $fileHelper, | ||
Parser $currentPhpVersionRichParser, | ||
Parser $currentPhpVersionSimpleParser, | ||
Parser $php8Parser | ||
) { | ||
$this->currentPhpVersionRichParser = $currentPhpVersionRichParser; | ||
parent::__construct($fileHelper, $currentPhpVersionRichParser, $currentPhpVersionSimpleParser, $php8Parser); | ||
} | ||
|
||
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); | ||
} | ||
} |