diff --git a/composer.json b/composer.json index dbfbb10..f3584bd 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "require": { "php": "^7.2 || ^8", "composer/semver": "^1.4 || ^2.0 || ^3.0", - "vimeo/psalm": "^4.28" + "vimeo/psalm": "^4.28|^5.0" }, "conflict": { "doctrine/collections": "<1.8", @@ -48,7 +48,8 @@ "config": { "sort-packages": true, "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "composer/package-versions-deprecated": true } }, "extra": { diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 1b4a7a0..8256af4 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -12,6 +12,7 @@ stubs tests */tests/_run/* + */tests/_support/_generated/* @@ -30,6 +31,8 @@ + + diff --git a/src/Provider/ReturnTypeProvider/CollectionFirstAndLast.php b/src/Provider/ReturnTypeProvider/CollectionFirstAndLast.php index 0e556e3..eb00d79 100644 --- a/src/Provider/ReturnTypeProvider/CollectionFirstAndLast.php +++ b/src/Provider/ReturnTypeProvider/CollectionFirstAndLast.php @@ -93,7 +93,7 @@ public static function getMethodReturnType(MethodReturnTypeProviderEvent $event) return null; } - $childNode = $type->getChildNodes(); + $childNode = $type->type_params; if (! isset($childNode[1]) || ! $childNode[1] instanceof Type\Union) { return null; } diff --git a/tests/acceptance/Collections.feature b/tests/acceptance/Collections.feature index 02a38fe..e95526b 100644 --- a/tests/acceptance/Collections.feature +++ b/tests/acceptance/Collections.feature @@ -41,19 +41,36 @@ Feature: Collections @Collection::add - Scenario: Adding an item of invalid type to the collection + Scenario: Adding an item of invalid type to the collection [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->add(1); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::add expects string, but 1 provided | And I see no other errors + @Collection::add + Scenario: Adding an item of invalid type to the collection [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->add(1); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 1 of Doctrine\Common\Collections\Collection::add expects string, but 1 provided | + And I see no other errors + + @Collection::add Scenario: Adding an item of a valid type to the collection Given I have the following code @@ -66,19 +83,35 @@ Feature: Collections Then I see no errors @Collection::contains - Scenario: Checking if collection contains an element of invalid type + Scenario: Checking if collection contains an element of invalid type [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->contains(1); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::contains expects string, but 1 provided | And I see no other errors + @Collection::contains + Scenario: Checking if collection contains an element of invalid type [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->contains(1); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 1 of Doctrine\Common\Collections\Collection::contains expects string, but 1 provided | + And I see no other errors + @Collection::contains Scenario: Checking if collection contains an element of a valid type Given I have the following code @@ -91,19 +124,35 @@ Feature: Collections Then I see no errors @Collection::remove - Scenario: Removing element with an invalid key type from the collection + Scenario: Removing element with an invalid key type from the collection [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->remove("string key"); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::remove expects int, but "string key" provided | And I see no other errors + @Collection::remove + Scenario: Removing element with an invalid key type from the collection [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->remove("string key"); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 1 of Doctrine\Common\Collections\Collection::remove expects int, but 'string key' provided | + And I see no other errors + @Collection::remove Scenario: Removing element with a valid key type from the collection Given I have the following code @@ -119,19 +168,35 @@ Feature: Collections And I see no other errors @Collection::removeElement - Scenario: Removing element of an invalid type from the collection + Scenario: Removing element of an invalid type from the collection [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->removeElement(1); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::removeElement expects string, but 1 provided | And I see no other errors + @Collection::removeElement + Scenario: Removing element of an invalid type from the collection [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->removeElement(1); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 1 of Doctrine\Common\Collections\Collection::removeElement expects string, but 1 provided | + And I see no other errors + @Collection::removeElement Scenario: Removing element of a valid type from the collection Given I have the following code @@ -147,19 +212,35 @@ Feature: Collections And I see no other errors @Collection::containsKey - Scenario: Checking if collection contains a key with invalid key type + Scenario: Checking if collection contains a key with invalid key type [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->containsKey("string key"); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::containsKey expects int, but "string key" provided | And I see no other errors + @Collection::containsKey + Scenario: Checking if collection contains a key with invalid key type [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->containsKey("string key"); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 1 of Doctrine\Common\Collections\Collection::containsKey expects int, but 'string key' provided | + And I see no other errors + @Collection::containsKey Scenario: Checking if collection contains a key with valid key type Given I have the following code @@ -172,19 +253,35 @@ Feature: Collections Then I see no errors @Collection::get - Scenario: Getting an element from the collection using invalid key type + Scenario: Getting an element from the collection using invalid key type [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->get("string key"); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::get expects int, but "string key" provided | And I see no other errors + @Collection::get + Scenario: Getting an element from the collection using invalid key type [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->get("string key"); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 1 of Doctrine\Common\Collections\Collection::get expects int, but 'string key' provided | + And I see no other errors + @Collection::get Scenario: Getting an element from the collection using a valid key type Given I have the following code @@ -209,7 +306,7 @@ Feature: Collections """ When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidArgument | Argument 1 of atan expects float, but list provided | And I see no other errors @@ -223,38 +320,70 @@ Feature: Collections """ When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidArgument | Argument 1 of atan expects float, but list provided | And I see no other errors @Collection::set - Scenario: Setting collection entry with invalid key + Scenario: Setting collection entry with invalid key [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->set("string key", "d"); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::set expects int, but "string key" provided | And I see no other errors @Collection::set - Scenario: Setting collection entry with invalid value + Scenario: Setting collection entry with invalid key [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->set("string key", "d"); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 1 of Doctrine\Common\Collections\Collection::set expects int, but 'string key' provided | + And I see no other errors + + @Collection::set + Scenario: Setting collection entry with invalid value [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->set(1, 1); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 2 of Doctrine\Common\Collections\Collection::set expects string, but 1 provided | And I see no other errors + @Collection::set + Scenario: Setting collection entry with invalid value [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->set(1, 1); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 2 of Doctrine\Common\Collections\Collection::set expects string, but 1 provided | + And I see no other errors + @Collection::toArray Scenario: Getting array of collection contents Given I have the following code @@ -295,7 +424,7 @@ Feature: Collections """ When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of atan expects float, but string provided | And I see no other errors @@ -311,7 +440,7 @@ Feature: Collections """ When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of atan expects float, but string provided | And I see no other errors @@ -328,7 +457,7 @@ Feature: Collections """ When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of atan expects float, but string provided | And I see no other errors @@ -343,7 +472,7 @@ Feature: Collections """ When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of atan expects float, but string provided | And I see no other errors @@ -373,7 +502,7 @@ Feature: Collections """ When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of atan expects float, but string provided | And I see no other errors @@ -389,7 +518,7 @@ Feature: Collections """ When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of atan expects float, but string provided | And I see no other errors @@ -450,19 +579,35 @@ Feature: Collections And I see no other errors @Collection::exists - Scenario: Invoking exists with a closure having a wrong return type + Scenario: Invoking exists with a closure having a wrong return type [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->exists(function(int $_k, string $_v): int { return rand(0,1); }); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | /Argument 1 of Doctrine\\Common\\Collections\\Collection::exists expects Closure\(int=, string=\):bool, but (impure-)?Closure\(int, string\):int(<0, 1>)? provided/ | And I see no other errors + @Collection::exists + Scenario: Invoking exists with a closure having a wrong return type [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->exists(function(int $_k, string $_v): int { return rand(0,1); }); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | /Argument 1 of Doctrine\\Common\\Collections\\Collection::exists expects Closure\(int=, string=\):bool, but (impure-)?Closure\(int, string\):int(<0, 1>)? provided/ | + And I see no other errors + @Collection::exists Scenario: Invoking exists with a closure accepting just keys Given I have the following code @@ -514,19 +659,35 @@ Feature: Collections And I see no other errors @Collection::filter - Scenario: Invoking filter with a closure having wrong return type + Scenario: Invoking filter with a closure having wrong return type [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->filter(function(string $_p): int { return rand(0,1); }); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | /Argument 1 of Doctrine\\Common\\Collections\\Collection::filter expects Closure\(string=\):bool, but (impure-)?Closure\(string\):int(<0, 1>)? provided/ | And I see no other errors + @Collection::filter + Scenario: Invoking filter with a closure having wrong return type [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->filter(function(string $_p): int { return rand(0,1); }); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | /Argument 1 of Doctrine\\Common\\Collections\\Collection::filter expects Closure\(string=\):bool, but (impure-)?Closure\(string\):int(<0, 1>)? provided/ | + And I see no other errors + # TODO: find out if this is applicable # Might need to be fixed upstream as well # @Collection::filter @@ -580,19 +741,35 @@ Feature: Collections And I see no other errors @Collection::forAll - Scenario: Invoking forAll with a closure having wrong return type + Scenario: Invoking forAll with a closure having wrong return type [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->forAll(function(int $_k, string $_v): int { return rand(0,1); }); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | /Argument 1 of Doctrine\\Common\\Collections\\Collection::forAll expects Closure\(int=, string=\):bool, but (impure-)?Closure\(int, string\):int(<0, 1>)? provided/ | And I see no other errors + @Collection::forAll + Scenario: Invoking forAll with a closure having wrong return type [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->forAll(function(int $_k, string $_v): int { return rand(0,1); }); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | /Argument 1 of Doctrine\\Common\\Collections\\Collection::forAll expects Closure\(int=, string=\):bool, but (impure-)?Closure\(int, string\):int(<0, 1>)? provided/ | + And I see no other errors + @Collection::forAll Scenario: Invoking forAll with a closure accepting just keys Given I have the following code @@ -683,19 +860,35 @@ Feature: Collections And I see no other errors @Collection::partition - Scenario: Invoking partition with a closure having wrong return type + Scenario: Invoking partition with a closure having wrong return type [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->partition(function(int $_p): int { return rand(0,1); }); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | /Argument 1 of Doctrine\\Common\\Collections\\Collection::partition expects Closure\(int=, string=\):bool, but (impure-)?Closure\(int\):int(<0, 1>)? provided/ | And I see no other errors + @Collection::partition + Scenario: Invoking partition with a closure having wrong return type [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->partition(function(int $_p): int { return rand(0,1); }); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | /Argument 1 of Doctrine\\Common\\Collections\\Collection::partition expects Closure\(int=, string=\):bool, but (impure-)?Closure\(int\):int(<0, 1>)? provided/ | + And I see no other errors + @Collection::partition Scenario: Invoking partition with a closure accepting nothing Given I have the following code @@ -708,19 +901,36 @@ Feature: Collections Then I see no errors @Collection::indexOf - Scenario: Invoking indexOf with a wrong type + Scenario: Invoking indexOf with a wrong type [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->indexOf(1); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::indexOf expects string, but 1 provided | And I see no other errors + @Collection::indexOf + Scenario: Invoking indexOf with a wrong type [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->indexOf(1); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 1 of Doctrine\Common\Collections\Collection::indexOf expects string, but 1 provided | + And I see no other errors + + @Collection::indexOf Scenario: Invoking indexOf with a proper type Given I have the following code @@ -736,33 +946,65 @@ Feature: Collections And I see no other errors @Collection::slice - Scenario: Invoking slice with a wrong start offset + Scenario: Invoking slice with a wrong start offset [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->slice("string key"); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::slice expects int, but "string key" provided | And I see no other errors @Collection::slice - Scenario: Invoking slice with a wrong length + Scenario: Invoking slice with a wrong start offset [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->slice("string key"); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 1 of Doctrine\Common\Collections\Collection::slice expects int, but 'string key' provided | + And I see no other errors + + @Collection::slice + Scenario: Invoking slice with a wrong length [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c->slice(1, "zzzz"); """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 2 of Doctrine\Common\Collections\Collection::slice expects int\|null, but "zzzz" provided | And I see no other errors + @Collection::slice + Scenario: Invoking slice with a wrong length [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c->slice(1, "zzzz"); + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 2 of Doctrine\Common\Collections\Collection::slice expects int\|null, but 'zzzz' provided | + And I see no other errors + @Collection::slice Scenario: Invoking slice with correct param types Given I have the following code @@ -815,13 +1057,14 @@ Feature: Collections Then I see no errors @Collections::ArrayAccess - Scenario: Adding an item of a wrong type with array-like push + Scenario: Adding an item of a wrong type with array-like push [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c[] = 1.1; """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors | Type | Message | @@ -829,13 +1072,30 @@ Feature: Collections And I see no other errors @Collections::ArrayAccess - Scenario: Adding an item using wrong type with array offset access + Scenario: Adding an item of a wrong type with array-like push [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c[] = 1.1; + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 2 of Doctrine\Common\Collections\Collection::offsetSet expects string, but float(1.1) provided | + And I see no other errors + + + @Collections::ArrayAccess + Scenario: Adding an item using wrong type with array offset access [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c[10] = 1.1; """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors | Type | Message | @@ -843,24 +1103,68 @@ Feature: Collections And I see no other errors @Collections::ArrayAccess - Scenario: Adding an item using wrong key type with array offset access + Scenario: Adding an item using wrong type with array offset access [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c[10] = 1.1; + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 2 of Doctrine\Common\Collections\Collection::offsetSet expects string, but float(1.1) provided | + And I see no other errors + + @Collections::ArrayAccess + Scenario: Adding an item using wrong key type with array offset access [Psalm 4] Given I have the following code """ /** @var Collection */ $c = new ArrayCollection(["a", "b", "c"]); $c["10"] = "aaa"; """ + And I have Psalm older than "5.0" (because of "changed issue type") When I run Psalm Then I see these errors - | Type | Message | + | Type | Message | | InvalidScalarArgument | Argument 1 of Doctrine\Common\Collections\Collection::offsetSet expects int\|null, but "10" provided | And I see no other errors + @Collections::ArrayAccess + Scenario: Adding an item using wrong key type with array offset access [Psalm 5] + Given I have the following code + """ + /** @var Collection */ + $c = new ArrayCollection(["a", "b", "c"]); + $c["10"] = "aaa"; + """ + And I have Psalm newer than "4.99" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 1 of Doctrine\Common\Collections\Collection::offsetGet expects int\|null, but '10' provided | + | InvalidArgument | Argument 1 of Doctrine\Common\Collections\Collection::offsetSet expects int\|null, but '10' provided | + And I see no other errors + + @Collections::ArrayCollection + Scenario: Extending ArrayCollection gives no error [Psalm 4] + Given I have the following code + """ + class MyCollection extends ArrayCollection {} + """ + And I have Psalm older than "5.0" (because of "template parameter requirements") + When I run Psalm + Then I see no errors + @Collections::ArrayCollection - Scenario: Extending ArrayCollection gives no error + Scenario: Extending ArrayCollection gives no error [Psalm 5] Given I have the following code """ + /** @template-extends ArrayCollection */ class MyCollection extends ArrayCollection {} """ + And I have Psalm newer than "4.99" (because of "template parameter requirements") When I run Psalm - Then I see no error + Then I see no errors diff --git a/tests/acceptance/QueryBuilder.feature b/tests/acceptance/QueryBuilder.feature index 44a06f6..c66d717 100644 --- a/tests/acceptance/QueryBuilder.feature +++ b/tests/acceptance/QueryBuilder.feature @@ -97,16 +97,30 @@ Feature: QueryBuilder | ImplicitToStringCast | Argument 1 of Doctrine\ORM\QueryBuilder::select expects Doctrine\ORM\Query\Expr\Func\|array\|null\|string, but Doctrine\ORM\Query\Expr\Andx provided with a __toString method | @QueryBuilder - Scenario: QueryBuilder::select() rejects wrong non-stringable arguments + Scenario: QueryBuilder::select() rejects wrong non-stringable arguments [Psalm 4] Given I have the following code """ builder()->select(2.2)->distinct(); """ + And I have Psalm older than "5.0.0" (because of "changed issue type") When I run Psalm Then I see these errors | Type | Message | | InvalidScalarArgument | Argument 1 of Doctrine\ORM\QueryBuilder::select expects Doctrine\ORM\Query\Expr\Func\|array\|null\|string, but float(2.2) provided | + @QueryBuilder + Scenario: QueryBuilder::select() rejects wrong non-stringable arguments [Psalm 5] + Given I have the following code + """ + builder()->select(2.2)->distinct(); + """ + And I have Psalm newer than "4.99.0" (because of "changed issue type") + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 1 of Doctrine\ORM\QueryBuilder::select expects Doctrine\ORM\Query\Expr\Func\|array\|null\|string, but float(2.2) provided | + + @QueryBuilder Scenario: QueryBuilder ::where(), ::orWhere() and ::andWhere accept Expr\Comparison Given I have the following code