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: 2 additions & 0 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\Analyser\ScopeFactory;
use PHPStan\Parser\Parser;
use PHPStan\Php\PhpVersionFactory;
use PHPStan\PhpDoc\TypeNodeResolver;
use PHPStan\PhpDocParser\ParserConfig;
use PHPStan\Reflection\ReflectionProvider;
Expand Down Expand Up @@ -311,6 +312,7 @@ final class LazyContainerFactory
TypeNodeResolver::class,
NodeScopeResolver::class,
ReflectionProvider::class,
PhpVersionFactory::class,
];

/**
Expand Down
30 changes: 30 additions & 0 deletions tests/DependencyInjection/PhpVersionFactoryAutowireTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\DependencyInjection;

use PHPStan\Php\PhpVersionFactory;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Rector\Tests\DependencyInjection\Source\HasPhpVersionFactoryDependency;

/**
* Regression test for a container that cannot autowire the PHPStan PhpVersionFactory,
* whose constructor has non-class scalar parameters (?int $versionId, ?string $composerPhpVersion).
*
* 3rd-party rules like drupal-rector's FunctionalTestDefaultThemePropertyRector inject it directly.
*/
final class PhpVersionFactoryAutowireTest extends AbstractLazyTestCase
{
public function testResolvedDirectly(): void
{
$phpVersionFactory = $this->make(PhpVersionFactory::class);
$this->assertInstanceOf(PhpVersionFactory::class, $phpVersionFactory);
}

public function testResolvedAsConstructorDependency(): void
{
$hasPhpVersionFactoryDependency = $this->make(HasPhpVersionFactoryDependency::class);
$this->assertInstanceOf(PhpVersionFactory::class, $hasPhpVersionFactoryDependency->getPhpVersionFactory());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\DependencyInjection\Source;

use PHPStan\Php\PhpVersionFactory;

/**
* Mimics 3rd-party rules (e.g. drupal-rector's FunctionalTestDefaultThemePropertyRector)
* that inject the PHPStan PhpVersionFactory service via constructor.
*/
final readonly class HasPhpVersionFactoryDependency
{
public function __construct(
private PhpVersionFactory $phpVersionFactory
) {
}

public function getPhpVersionFactory(): PhpVersionFactory
{
return $this->phpVersionFactory;
}
}
Loading