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 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", diff --git a/src/AbstractLazyCollection.php b/src/AbstractLazyCollection.php index 222bbe1b..e7a2d686 100644 --- a/src/AbstractLazyCollection.php +++ b/src/AbstractLazyCollection.php @@ -177,13 +177,7 @@ public function findFirst(Closure $p): mixed return $this->collection->findFirst($p); } - /** - * @psalm-param Closure(T, TKey):bool $p - * - * @return ReadableCollection - * @psalm-return ReadableCollection - */ - public function filter(Closure $p): ReadableCollection + public function filter(Closure $p): Collection { $this->initialize(); @@ -197,15 +191,7 @@ public function forAll(Closure $p): bool return $this->collection->forAll($p); } - /** - * @psalm-param Closure(T):U $func - * - * @return ReadableCollection - * @psalm-return ReadableCollection - * - * @psalm-template U - */ - public function map(Closure $func): ReadableCollection + public function map(Closure $func): Collection { $this->initialize(); diff --git a/src/Collection.php b/src/Collection.php index fb3b5baf..3dc56ac3 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. @@ -73,4 +74,34 @@ public function removeElement(mixed $element): bool; * @psalm-param T $value */ public function set(string|int $key, mixed $value): void; + + /** + * {@inheritDoc} + * + * @psalm-param Closure(T):U $func + * + * @return Collection + * @psalm-return Collection + * + * @psalm-template U + */ + public function map(Closure $func): self; + + /** + * {@inheritDoc} + * + * @return Collection A collection with the results of the filter operation. + * @psalm-return Collection + */ + public function filter(Closure $p): self; + + /** + * {@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): array; }