mirror of
https://github.com/danog/psalm-plugin-symfony.git
synced 2024-11-26 20:04:58 +01:00
[chore] organize stubs matching namespaces (#210)
fixes https://github.com/psalm/psalm-plugin-symfony/issues/209
This commit is contained in:
parent
9b2232bec7
commit
97f0652612
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Psalm\SymfonyPsalmPlugin;
|
||||
|
||||
use function array_merge;
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
use Psalm\Exception\ConfigException;
|
||||
use Psalm\Plugin\PluginEntryPointInterface;
|
||||
@ -29,30 +28,6 @@ use Symfony\Component\HttpKernel\Kernel;
|
||||
*/
|
||||
class Plugin implements PluginEntryPointInterface
|
||||
{
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getCommonStubs(): array
|
||||
{
|
||||
// GLOB_BRACE is undefined on Alpine Linux https://bugs.php.net/bug.php?id=72095
|
||||
return array_merge(
|
||||
glob(__DIR__.'/Stubs/common/*/*.stubphp'),
|
||||
glob(__DIR__.'/Stubs/common/*.stubphp')
|
||||
) ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $majorVersion symfony major version
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getStubsForMajorVersion(int $majorVersion): array
|
||||
{
|
||||
$version = (string) $majorVersion;
|
||||
|
||||
return glob(__DIR__.'/Stubs/'.$version.'/*.stubphp') ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -95,14 +70,8 @@ class Plugin implements PluginEntryPointInterface
|
||||
|
||||
$api->registerHooksFromClass(ContainerHandler::class);
|
||||
|
||||
$stubs = array_merge(
|
||||
$this->getCommonStubs(),
|
||||
$this->getStubsForMajorVersion(Kernel::MAJOR_VERSION)
|
||||
);
|
||||
|
||||
foreach ($stubs as $stubFilePath) {
|
||||
$api->addStubFile($stubFilePath);
|
||||
}
|
||||
$this->addStubs($api, __DIR__.'/Stubs/common');
|
||||
$this->addStubs($api, __DIR__.'/Stubs/'.Kernel::MAJOR_VERSION);
|
||||
|
||||
if (isset($config->twigCachePath)) {
|
||||
$twig_cache_path = getcwd().DIRECTORY_SEPARATOR.ltrim((string) $config->twigCachePath, DIRECTORY_SEPARATOR);
|
||||
@ -131,4 +100,14 @@ class Plugin implements PluginEntryPointInterface
|
||||
TemplateFileAnalyzer::setTemplateRootPath($twig_root_path);
|
||||
}
|
||||
}
|
||||
|
||||
private function addStubs(RegistrationInterface $api, string $path): void
|
||||
{
|
||||
$a = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
|
||||
foreach ($a as $file) {
|
||||
if (!$file->isDir()) {
|
||||
$api->addStubFile($file->getPathname());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user