From e626923600b622b5c6ed4893bc18dd7f68183fc0 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Sat, 20 Jul 2019 13:10:23 +0300 Subject: [PATCH] Disabled Collection stub for newer doctrine/collections versions Refs #21 --- src/Plugin.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 9b932c2..557f6a1 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -14,7 +14,11 @@ use function class_exists; use function explode; use function glob; +use function preg_grep; use function strpos; +use function version_compare; + +use const PREG_GREP_INVERT; class Plugin implements PluginEntryPointInterface { @@ -32,10 +36,16 @@ public function __invoke(RegistrationInterface $psalm, ?SimpleXMLElement $config /** @return string[] */ private function getStubFiles(): array { - return array_merge( - glob(__DIR__ . '/../stubs/*.phpstub') ?: [], - glob(__DIR__ . '/../stubs/DBAL/*.phpstub') ?: [] - ); + $files = glob(__DIR__ . '/../stubs/*.phpstub') ?: []; + + if ($this->hasPackage('doctrine/collections')) { + [$ver] = explode('@', $this->getPackageVersion('doctrine/collections')); + if (version_compare($ver, 'v1.6.0', '>=')) { + $files = preg_grep('/Collections\.phpstub$/', $files, PREG_GREP_INVERT); + } + } + + return array_merge($files, glob(__DIR__ . '/../stubs/DBAL/*.phpstub') ?: []); } private function hasPackage(string $packageName): bool