Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
-
name: 'Active Classes'
run: |
vendor/bin/class-leak check bin config src rules utils --skip-suffix "Rector" --skip-type="Rector\\Utils\\Compiler\\Unprefixer" --skip-type="Rector\\NodeCollector\\BinaryOpConditionsCollector" --skip-type="Rector\\Set\\Contract\\SetListInterface"
vendor/bin/class-leak check bin config src rules utils --skip-suffix "Rector" --skip-type="Rector\\Utils\\Compiler\\Unprefixer" --skip-type="Rector\\NodeCollector\\BinaryOpConditionsCollector" --skip-type="Rector\\Set\\Contract\\SetListInterface" --skip-type="Rector\\DependencyInjection\\PHPStan\\RichParserFactory"

-
name: 'Compatible PHPStan versions'
Expand Down
16 changes: 16 additions & 0 deletions config/phpstan/parser.neon
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ services:

rectorParser:
class: PHPStan\Parser\RichParser
factory: @rectorRichParserFactory::create()
arguments!: []
autowired: no

# RichParser used directly by Rector, see PHPStanServicesFactory::createPHPStanParser()
currentPhpVersionRichParser:
class: PHPStan\Parser\RichParser
factory: @rectorRichParserFactory::create()
arguments!: []
autowired: no

rectorRichParserFactory:
class: Rector\DependencyInjection\PHPStan\RichParserFactory
arguments:
parser: @currentPhpVersionPhpParser
nodeVisitors:
- @PHPStan\Parser\AnonymousClassVisitor
- @PHPStan\Parser\ArrayMapArgVisitor
autowired: no
42 changes: 0 additions & 42 deletions src/DependencyInjection/PHPStan/PHPStanContainerMemento.php

This file was deleted.

46 changes: 46 additions & 0 deletions src/DependencyInjection/PHPStan/RichParserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Rector\DependencyInjection\PHPStan;

use PhpParser\NodeVisitor;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\Parser;
use PHPStan\Analyser\Ignore\IgnoreLexer;
use PHPStan\DependencyInjection\DirectExtensionsCollection;
use PHPStan\Parser\RichParser;

/**
* Creates PHPStan RichParser with only the node visitors Rector needs,
* to avoid issues caused by node replacement, like @see https://github.com/rectorphp/rector/issues/9492
*
* The visitors have to be passed here, as PHPStan autowires them into every RichParser
* service definition, see PHPStan\DependencyInjection\AutowiredExtensionsExtension
*/
final readonly class RichParserFactory
{
/**
* @param NodeVisitor[] $nodeVisitors
*/
public function __construct(
private Parser $parser,
private NameResolver $nameResolver,
private IgnoreLexer $ignoreLexer,
private array $nodeVisitors
) {
}

/**
* @api used by config/phpstan/parser.neon
*/
public function create(): RichParser
{
return new RichParser(
$this->parser,
$this->nameResolver,
new DirectExtensionsCollection($this->nodeVisitors),
$this->ignoreLexer
);
}
}
3 changes: 0 additions & 3 deletions src/PhpParser/Parser/RectorParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PhpParser\PhpVersion;
use PHPStan\Parser\Parser;
use PHPStan\Parser\RichParser;
use Rector\DependencyInjection\PHPStan\PHPStanContainerMemento;
use Rector\PhpParser\ValueObject\StmtsAndTokens;
use Rector\Util\Reflection\PrivatesAccessor;

Expand All @@ -22,8 +21,6 @@ public function __construct(
private Parser $parser,
private PrivatesAccessor $privatesAccessor
) {

PHPStanContainerMemento::removeRichVisitors($parser);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions tests/PhpParser/Printer/PHPStanPrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PhpParser\PrettyPrinter\Standard;
use PHPStan\Parser\Parser;
use PHPStan\Parser\RichParser;
use Rector\DependencyInjection\PHPStan\PHPStanContainerMemento;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use ReflectionProperty;

Expand All @@ -24,8 +23,6 @@ public function testAddingCommentOnSomeNodesFail(): void
/** @var RichParser $phpstanParser */
$phpstanParser = $this->make(Parser::class);

PHPStanContainerMemento::removeRichVisitors($phpstanParser);

$stmts = $phpstanParser->parseFile(__DIR__ . '/Fixture/some_array_map.php');

// get private property "parser"
Expand Down
Loading