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

Feature/phpstan generics for collection #64

Merged
merged 14 commits into from
Dec 30, 2019

Conversation

nvdbeek
Copy link
Contributor

@nvdbeek nvdbeek commented Dec 30, 2019

Fix #63 . Add phpstan and psalm generics for the collections.

*/
public function __construct(array $elements = [], string $iteratorClass = \ArrayIterator::class)
final public function __construct(array $elements = [], string $iteratorClass = \ArrayIterator::class)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this final cause the following phpstan message:

  331    Unsafe usage of new static().                                                                                                                                                    
         💡 Consider making the class or the constructor final.   

Alternatively we can change new static() to new self() on line 367 and remove the unit tests that test this behaviour

Copy link
Contributor

@nusje2000 nusje2000 left a comment

Choose a reason for hiding this comment

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

Looks fine to me 👍

@aeviiq aeviiq changed the base branch from master to 3.1 December 30, 2019 15:10
@aeviiq aeviiq merged commit 8cfe1ce into aeviiq:3.1 Dec 30, 2019
@nvdbeek nvdbeek deleted the feature/phpstan-generics-for-collection branch December 30, 2019 16:19
@nvdbeek
Copy link
Contributor Author

nvdbeek commented Dec 31, 2019

Hi @aeviiq,

With the merge method is it possible to merge other collection instances into the collection with other instances. Whats your opinion about this? By merging this merge request it's no longer possible to merge 2 different instances into 1 collection.

Example:

/** @var PersonCollection<Person> $personCollection */
$personCollection = new PersonCollection();
$person = new Person();

$a = new Collection([$person]);
$a->merge($personCollection); // should work

/** @var ProductCollection<Product> $otherCollection */
$otherCollection = new ProductCollection();
$a->merge($otherCollection); // should give phpstan error (expects Person, ProductCollection given.)

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