Skip to content

Synchronize Collection::add with doctrine/collections #560

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

Merged
merged 5 commits into from
Apr 17, 2024

Conversation

VincentLanglet
Copy link
Contributor

Hi,

Collection::add returns void and not true according to doctrine/collections
https://github.com/doctrine/collections/blob/9b9c38a3eff3c7477989129b096d21e2b1710ee0/src/Collection.php#L34-L42

@janedbal
Copy link
Contributor

What about older versions? I see true in 1.8.0

@VincentLanglet
Copy link
Contributor Author

What about older versions? I see true in 1.8.0

Oh, do we have to duplicate the stub then ?
or drop old version of doctrine/collection ? (https://github.com/doctrine/collections/releases/tag/1.8.0 was released in 2022)

@ondrejmirtes
Copy link
Member

We need conditional including of different stubs based on the version. In a StubFilesExtension.

@VincentLanglet
Copy link
Contributor Author

We need conditional including of different stubs based on the version. In a StubFilesExtension.

Done

@@ -59,6 +61,13 @@ public function getFiles(): array
$files[] = $stubsDir . '/ServiceEntityRepository.stub';
}

$collectionVersion = InstalledVersions::getVersion('doctrine/dbal');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check that InstalledVersions class exists.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking, we should even catch OutOfBoundsException in case dbal is not installed: https://getcomposer.org/doc/07-runtime.md#knowing-the-version-of-package-x

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh damn, and the check should be about 'doctrine/collections' not 'doctrine/dbal'.

I fixed it and added a class_exists check and the try/catch of OutOfBoundsException.

@ondrejmirtes ondrejmirtes merged commit 849b856 into phpstan:1.4.x Apr 17, 2024
28 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

@VincentLanglet
Copy link
Contributor Author

I messed up and target 1.4.x instead of 1.3.x.

Should I reopen a PR on 1.3.x @ondrejmirtes ?

@ondrejmirtes
Copy link
Member

No, you'll have to wait for release alongside PHPStan 1.11 😊 shouldn't be too far off

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants