Skip to content

Commit a4c88df

Browse files
committed
try to remove breaking service from container
1 parent ea9a6ad commit a4c88df

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"nikic/php-parser": "^5.6.2",
2424
"ondram/ci-detector": "^4.2",
2525
"phpstan/phpdoc-parser": "^2.3",
26-
"phpstan/phpstan": "2.1.19 as 2.1.32",
26+
"phpstan/phpstan": "^2.1.32",
2727
"react/event-loop": "^1.6",
2828
"react/promise": "^3.3",
2929
"react/socket": "^1.17",

tests/PhpParser/Printer/PHPStanPrinterTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
namespace Rector\Tests\PhpParser\Printer;
66

77
use PhpParser\PrettyPrinter\Standard;
8+
use PHPStan\DependencyInjection\MemoizingContainer;
9+
use PHPStan\DependencyInjection\Nette\NetteContainer;
810
use PHPStan\Parser\Parser;
911
use PHPStan\Parser\RichParser;
1012
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
13+
use Rector\Util\Reflection\PrivatesAccessor;
1114

1215
/**
1316
* Test case for: https://github.com/rectorphp/rector/issues/9492
@@ -20,6 +23,30 @@ public function testAddingCommentOnSomeNodesFail(): void
2023
/** @var RichParser $phpstanParser */
2124
$phpstanParser = $this->make(Parser::class);
2225

26+
// the only way now seems to access container early and remove unwanted services
27+
// here https://github.com/phpstan/phpstan-src/blob/522421b007cbfc674bebb93e823c774167ac78cd/src/Parser/RichParser.php#L90-L92
28+
$privatesAccessor = new PrivatesAccessor();
29+
30+
/** @var MemoizingContainer $container */
31+
$container = $privatesAccessor->getPrivateProperty($phpstanParser, 'container');
32+
33+
/** @var NetteContainer $originalContainer */
34+
$originalContainer = $privatesAccessor->getPrivateProperty($container, 'originalContainer');
35+
36+
/** @var NetteContainer $originalContainer */
37+
$deeperContainer = $privatesAccessor->getPrivateProperty($originalContainer, 'container');
38+
39+
// @todo
40+
41+
// get tags property
42+
$tags = $privatesAccessor->getPrivateProperty($deeperContainer, 'tags');
43+
44+
dump($tags);
45+
die;
46+
47+
dump($container->getServicesByTag(RichParser::VISITOR_SERVICE_TAG));
48+
die;
49+
2350
$stmts = $phpstanParser->parseFile(__DIR__ . '/Fixture/some_array_map.php');
2451

2552
// get private property "parser"

0 commit comments

Comments
 (0)