From 6a5a02b7588e491272d445fb169dcc9d9f1e60a5 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 24 Jul 2023 13:42:58 +0200 Subject: [PATCH 1/7] Doctrine Coding Standard 12 (#376) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 36ad7f1a..ff939f36 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ }, "require-dev": { "ext-json": "*", - "doctrine/coding-standard": "^10.0", + "doctrine/coding-standard": "^12", "phpstan/phpstan": "^1.8", "phpstan/phpstan-phpunit": "^1.0", "phpunit/phpunit": "^9.5", From 9eaa83917607cb26a397de7d1f786e9316265c41 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 30 Jul 2023 12:00:45 +0200 Subject: [PATCH 2/7] Add doctrine-project.json to .gitattributes (#377) --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index eead063b..e5239788 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ /tests export-ignore /.github export-ignore +.doctrine-project.json export-ignore .gitattributes export-ignore .gitignore export-ignore .scrutinizer.yml export-ignore From e69534975912887270ec4be5494743d596d25f68 Mon Sep 17 00:00:00 2001 From: Andreas Heigl Date: Fri, 29 Sep 2023 08:26:51 +0200 Subject: [PATCH 3/7] Make returntypes consistend with implementation (#379) --- src/AbstractLazyCollection.php | 12 +----------- src/Collection.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/AbstractLazyCollection.php b/src/AbstractLazyCollection.php index 5d309a5d..56a340bf 100644 --- a/src/AbstractLazyCollection.php +++ b/src/AbstractLazyCollection.php @@ -230,10 +230,7 @@ public function findFirst(Closure $p) } /** - * @psalm-param Closure(T, TKey):bool $p - * - * @return ReadableCollection - * @psalm-return ReadableCollection + * {@inheritDoc} */ public function filter(Closure $p) { @@ -254,13 +251,6 @@ public function forAll(Closure $p) /** * {@inheritDoc} - * - * @psalm-param Closure(T):U $func - * - * @return ReadableCollection - * @psalm-return ReadableCollection - * - * @psalm-template U */ public function map(Closure $func) { diff --git a/src/Collection.php b/src/Collection.php index b93f1d00..e9fb58ed 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -5,6 +5,7 @@ namespace Doctrine\Common\Collections; use ArrayAccess; +use Closure; /** * The missing (SPL) Collection/Array/OrderedMap interface. @@ -79,4 +80,24 @@ public function removeElement(mixed $element); * @return void */ public function set(string|int $key, mixed $value); + + /** + * {@inheritDoc} + * + * @psalm-param Closure(T):U $func + * + * @return Collection + * @psalm-return Collection + * + * @psalm-template U + */ + public function map(Closure $func); + + /** + * {@inheritDoc} + * + * @return Collection A collection with the results of the filter operation. + * @psalm-return Collection + */ + public function filter(Closure $p); } From 72328a11443a0de79967104ad36ba7b30bded134 Mon Sep 17 00:00:00 2001 From: Andreas Heigl Date: Tue, 3 Oct 2023 11:22:33 +0200 Subject: [PATCH 4/7] Improve return type for Collection::partition (#380) Currently when partitioning a Collection-object it will return an array of ReadableCollections unless that return-type is overwritten in the implementation. This change makes sure that any implementation of a Collection actually returns an array of Collections instead. --- src/Collection.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Collection.php b/src/Collection.php index e9fb58ed..5a763cea 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -100,4 +100,14 @@ public function map(Closure $func); * @psalm-return Collection */ public function filter(Closure $p); + + /** + * {@inheritDoc} + + * @return Collection[] An array with two elements. The first element contains the collection + * of elements where the predicate returned TRUE, the second element + * contains the collection of elements where the predicate returned FALSE. + * @psalm-return array{0: Collection, 1: Collection} + */ + public function partition(Closure $p); } From 448e610677cfdad520382d9382fde5fff43ccec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 3 Oct 2023 17:14:35 +0200 Subject: [PATCH 5/7] Inherit annotations This implies disabling the UselessInheritDocComment sniff. --- phpcs.xml.dist | 4 +++- src/AbstractLazyCollection.php | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 10f6681b..29a7dde4 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -14,7 +14,9 @@ src tests - + + + tests/* diff --git a/src/AbstractLazyCollection.php b/src/AbstractLazyCollection.php index e7a2d686..c926b6d8 100644 --- a/src/AbstractLazyCollection.php +++ b/src/AbstractLazyCollection.php @@ -177,6 +177,9 @@ public function findFirst(Closure $p): mixed return $this->collection->findFirst($p); } + /** + * {@inheritDoc} + */ public function filter(Closure $p): Collection { $this->initialize(); @@ -191,6 +194,9 @@ public function forAll(Closure $p): bool return $this->collection->forAll($p); } + /** + * {@inheritDoc} + */ public function map(Closure $func): Collection { $this->initialize(); From b8145b95f42eec6b3734f0c39d9bc8838767a110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 3 Oct 2023 21:08:38 +0200 Subject: [PATCH 6/7] Disable UselessInheritDocComment sniff (#382) According to a maintainer of slevomat/coding-standard, it goes against other sniffs we use in this repository. See https://github.com/doctrine/collections/pull/381#issuecomment-1745206747 --- phpcs.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 693e0022..10cec0c5 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -15,6 +15,7 @@ tests + From f357734e0930dda758791e3b62a15543ad89a3e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 3 Oct 2023 22:11:29 +0200 Subject: [PATCH 7/7] Add comment explaining exclusion rule --- phpcs.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 10cec0c5..a5d8d83a 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -15,6 +15,7 @@ tests +