Skip to content

Commit

Permalink
Disabled Collection stub for newer doctrine/collections versions
Browse files Browse the repository at this point in the history
Refs #21
  • Loading branch information
weirdan authored and Mika56 committed Oct 24, 2023
1 parent e6c6bdd commit e626923
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down

0 comments on commit e626923

Please sign in to comment.