Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Collection stub for newer doctrine/collections versions #149

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
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
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
Loading