Skip to content
Open
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
16 changes: 1 addition & 15 deletions src/Stubs/Symfony/StubFilesExtensionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Composer\InstalledVersions;
use OutOfBoundsException;
use PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound;
use PHPStan\BetterReflection\Reflector\Reflector;
use PHPStan\PhpDoc\StubFilesExtension;
use function class_exists;
use function dirname;
Expand All @@ -14,15 +12,6 @@
class StubFilesExtensionLoader implements StubFilesExtension
{

private Reflector $reflector;

public function __construct(
Reflector $reflector
)
{
$this->reflector = $reflector;
}

public function getFiles(): array
{
$stubsDir = dirname(dirname(dirname(__DIR__))) . '/stubs';
Expand Down Expand Up @@ -82,12 +71,9 @@ public function getFiles(): array
if ($this->isInstalledVersionBelow('symfony/http-foundation', '7.4.0.0')) {
$files[] = $stubsDir . '/Symfony/Component/HttpFoundation/ParameterBag.stub';

try {
$this->reflector->reflectClass('Symfony\Component\HttpFoundation\InputBag');
if (!$this->isInstalledVersionBelow('symfony/http-foundation', '5.1.0.0')) {
$files[] = $stubsDir . '/Symfony/Component/HttpFoundation/InputBag.stub';
$files[] = $stubsDir . '/Symfony/Component/HttpFoundation/Request.stub';
} catch (IdentifierNotFound $e) {
// Don't load the InputBag and the associated Request stubs for older Symfony versions that did not have InputBag yet to avoid breaking the Request.
}
}

Expand Down
26 changes: 26 additions & 0 deletions tests/Stubs/Symfony/StubFilesExtensionLoaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare(strict_types = 1);

namespace PHPStan\Stubs\Symfony;

use PHPStan\Testing\PHPStanTestCase;

final class StubFilesExtensionLoaderTest extends PHPStanTestCase
{

public function testGetFilesDoesNotUseSourceLocator(): void
{
$loader = self::getContainer()->getByType(StubFilesExtensionLoader::class);
foreach ($loader->getFiles() as $file) {
self::assertFileExists($file);
}
}

public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/../../../extension.neon',
__DIR__ . '/stub-loader-test.neon',
];
}

}
25 changes: 25 additions & 0 deletions tests/Stubs/Symfony/ThrowingSourceLocator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types = 1);

namespace PHPStan\Stubs\Symfony;

use PHPStan\BetterReflection\Identifier\Identifier;
use PHPStan\BetterReflection\Identifier\IdentifierType;
use PHPStan\BetterReflection\Reflection\Reflection;
use PHPStan\BetterReflection\Reflector\Reflector;
use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator;
use PHPUnit\Framework\Assert;

final class ThrowingSourceLocator implements SourceLocator
{

public function locateIdentifier(Reflector $reflector, Identifier $identifier): ?Reflection
{
Assert::fail('SourceLocator::locateIdentifier must not be called during getFiles()');
}

public function locateIdentifiersByType(Reflector $reflector, IdentifierType $identifierType): array
{
Assert::fail('SourceLocator::locateIdentifiersByType must not be called during getFiles()');
}

}
5 changes: 5 additions & 0 deletions tests/Stubs/Symfony/stub-loader-test.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
betterReflectionSourceLocator:
class: PHPStan\BetterReflection\SourceLocator\Type\SourceLocator
factory: PHPStan\Stubs\Symfony\ThrowingSourceLocator
autowired: false
Loading