-
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[config] include bootstrap files of extensions, to let rector know ab…
…out types as well (#3380) * [config] include bootstrap files of extensions, to let rector know about types as well * tidy * make fixtures unique to easier find
- Loading branch information
1 parent
dffddb2
commit 48228ed
Showing
15 changed files
with
220 additions
and
142 deletions.
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
36 changes: 36 additions & 0 deletions
36
packages-tests/NodeTypeResolver/DependencyInjection/PHPStanExtensionsConfigResolverTest.php
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\NodeTypeResolver\DependencyInjection; | ||
|
||
use Rector\NodeTypeResolver\DependencyInjection\PHPStanExtensionsConfigResolver; | ||
use Rector\Testing\PHPUnit\AbstractTestCase; | ||
|
||
final class PHPStanExtensionsConfigResolverTest extends AbstractTestCase | ||
{ | ||
private PHPStanExtensionsConfigResolver $phpStanExtensionsConfigResolver; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->boot(); | ||
|
||
$this->phpStanExtensionsConfigResolver = $this->getService(PHPStanExtensionsConfigResolver::class); | ||
} | ||
|
||
public function test(): void | ||
{ | ||
// these configs are required by this package, so must be in there | ||
|
||
$phpunitExtensionFilePath = realpath(__DIR__ . '/../../../vendor/phpstan/phpstan-phpunit/extension.neon'); | ||
|
||
$assertExtensionFilePath = realpath( | ||
__DIR__ . '/../../../vendor/phpstan/phpstan-webmozart-assert/extension.neon' | ||
); | ||
|
||
$extensionConfigFiles = $this->phpStanExtensionsConfigResolver->resolve(); | ||
|
||
$this->assertContains($phpunitExtensionFilePath, $extensionConfigFiles); | ||
$this->assertContains($assertExtensionFilePath, $extensionConfigFiles); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
packages/NodeTypeResolver/DependencyInjection/PHPStanExtensionsConfigResolver.php
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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\NodeTypeResolver\DependencyInjection; | ||
|
||
use PHPStan\ExtensionInstaller\GeneratedConfig; | ||
use Rector\Core\Exception\ShouldNotHappenException; | ||
use ReflectionClass; | ||
|
||
/** | ||
* @see \Rector\Tests\NodeTypeResolver\DependencyInjection\PHPStanExtensionsConfigResolverTest | ||
*/ | ||
final class PHPStanExtensionsConfigResolver | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private array $cachedExtensionConfigFiles = []; | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function resolve(): array | ||
{ | ||
// same logic as in PHPStan for extension installed - https://github.com/phpstan/phpstan-src/blob/5956ec4f6cd09c8d7db9466ed4e7f25706f37a43/src/Command/CommandHelper.php#L195-L222 | ||
if (! class_exists(GeneratedConfig::class)) { | ||
return []; | ||
} | ||
|
||
if ($this->cachedExtensionConfigFiles !== []) { | ||
return $this->cachedExtensionConfigFiles; | ||
} | ||
|
||
$reflectionClass = new ReflectionClass(GeneratedConfig::class); | ||
$generatedConfigClassFileName = $reflectionClass->getFileName(); | ||
if ($generatedConfigClassFileName === false) { | ||
throw new ShouldNotHappenException(); | ||
} | ||
|
||
$generatedConfigDirectory = dirname($generatedConfigClassFileName); | ||
|
||
$extensionConfigFiles = []; | ||
|
||
foreach (GeneratedConfig::EXTENSIONS as $extension) { | ||
$fileNames = $extension['extra']['includes'] ?? []; | ||
foreach ($fileNames as $fileName) { | ||
$configFilePath = $generatedConfigDirectory . '/' . $extension['relative_install_path'] . '/' . $fileName; | ||
|
||
$absoluteConfigFilePath = realpath($configFilePath); | ||
if (! is_string($absoluteConfigFilePath)) { | ||
continue; | ||
} | ||
|
||
$extensionConfigFiles[] = $absoluteConfigFilePath; | ||
} | ||
} | ||
|
||
$this->cachedExtensionConfigFiles = $extensionConfigFiles; | ||
|
||
return $extensionConfigFiles; | ||
} | ||
} |
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
28 changes: 0 additions & 28 deletions
28
rules-tests/Php80/Rector/FunctionLike/UnionTypesRector/AutoImportTest.php
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
...p80/Rector/FunctionLike/UnionTypesRector/FixtureAutoImport/do_not_import_iterable.php.inc
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
...s-tests/Php80/Rector/FunctionLike/UnionTypesRector/config/configured_rule_auto_import.php
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.