From dbf43a6b558c849d31b3ff16728ace444e82417d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Mon, 16 Dec 2024 16:34:37 +0100 Subject: [PATCH] Drop Psalm As per our decision during the hackathon --- .gitattributes | 1 - composer.json | 3 +- psalm.xml.dist | 63 ---------------------- src/AbstractLazyCollection.php | 12 ++--- src/ArrayCollection.php | 38 +++++++------ src/Collection.php | 30 +++++------ src/Criteria.php | 2 +- src/ReadableCollection.php | 66 +++++++++++------------ src/Selectable.php | 6 +-- tests/AbstractLazyCollectionTest.php | 2 +- tests/ArrayCollectionTestCase.php | 2 +- tests/StaticAnalysis/CustomCollection.php | 6 +-- 12 files changed, 82 insertions(+), 149 deletions(-) delete mode 100644 psalm.xml.dist diff --git a/.gitattributes b/.gitattributes index e5239788..869c7f98 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,4 +7,3 @@ phpunit.xml.dist export-ignore /phpcs.xml.dist export-ignore /phpstan.neon.dist export-ignore -/psalm.xml.dist export-ignore diff --git a/composer.json b/composer.json index 4c36229a..ac98cfbe 100644 --- a/composer.json +++ b/composer.json @@ -41,8 +41,7 @@ "doctrine/coding-standard": "^12", "phpstan/phpstan": "^1.8", "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^10.5", - "vimeo/psalm": "^5.11" + "phpunit/phpunit": "^10.5" }, "autoload": { "psr-4": { diff --git a/psalm.xml.dist b/psalm.xml.dist deleted file mode 100644 index aaa96c85..00000000 --- a/psalm.xml.dist +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/AbstractLazyCollection.php b/src/AbstractLazyCollection.php index 56a340bf..36e20860 100644 --- a/src/AbstractLazyCollection.php +++ b/src/AbstractLazyCollection.php @@ -12,8 +12,8 @@ /** * Lazy collection that is backed by a concrete collection * - * @psalm-template TKey of array-key - * @psalm-template T + * @phpstan-template TKey of array-key + * @phpstan-template T * @template-implements Collection */ abstract class AbstractLazyCollection implements Collection @@ -21,7 +21,7 @@ abstract class AbstractLazyCollection implements Collection /** * The backed collection to use * - * @psalm-var Collection|null + * @phpstan-var Collection|null * @var Collection|null */ protected Collection|null $collection; @@ -305,7 +305,7 @@ public function slice(int $offset, int|null $length = null) * {@inheritDoc} * * @return Traversable - * @psalm-return Traversable + * @phpstan-return Traversable */ #[ReturnTypeWillChange] public function getIterator() @@ -377,7 +377,7 @@ public function offsetUnset(mixed $offset) * * @return bool * - * @psalm-assert-if-true Collection $this->collection + * @phpstan-assert-if-true Collection $this->collection */ public function isInitialized() { @@ -389,7 +389,7 @@ public function isInitialized() * * @return void * - * @psalm-assert Collection $this->collection + * @phpstan-assert Collection $this->collection */ protected function initialize() { diff --git a/src/ArrayCollection.php b/src/ArrayCollection.php index 2e7d0e3b..7d6cf788 100644 --- a/src/ArrayCollection.php +++ b/src/ArrayCollection.php @@ -40,18 +40,18 @@ * serialize a collection use {@link toArray()} and reconstruct the collection * manually. * - * @psalm-template TKey of array-key - * @psalm-template T + * @phpstan-template TKey of array-key + * @phpstan-template T * @template-implements Collection * @template-implements Selectable - * @psalm-consistent-constructor + * @phpstan-consistent-constructor */ class ArrayCollection implements Collection, Selectable, Stringable { /** * An array containing the entries of this collection. * - * @psalm-var array + * @phpstan-var array * @var mixed[] */ private array $elements = []; @@ -59,7 +59,7 @@ class ArrayCollection implements Collection, Selectable, Stringable /** * Initializes a new ArrayCollection. * - * @psalm-param array $elements + * @phpstan-param array $elements */ public function __construct(array $elements = []) { @@ -89,13 +89,13 @@ public function first() * instance should be created when constructor semantics have changed. * * @param array $elements Elements. - * @psalm-param array $elements + * @phpstan-param array $elements * * @return static - * @psalm-return static + * @phpstan-return static * - * @psalm-template K of array-key - * @psalm-template V + * @phpstan-template K of array-key + * @phpstan-template V */ protected function createFrom(array $elements) { @@ -257,10 +257,10 @@ public function exists(Closure $p) /** * {@inheritDoc} * - * @psalm-param TMaybeContained $element + * @phpstan-param TMaybeContained $element * * @return int|string|false - * @psalm-return (TMaybeContained is T ? TKey|false : false) + * @phpstan-return (TMaybeContained is T ? TKey|false : false) * * @template TMaybeContained */ @@ -315,8 +315,6 @@ public function set(string|int $key, mixed $value) /** * {@inheritDoc} * - * @psalm-suppress InvalidPropertyAssignmentValue - * * This breaks assumptions about the template type, but it would * be a backwards-incompatible change to remove this method */ @@ -337,7 +335,7 @@ public function isEmpty() * {@inheritDoc} * * @return Traversable - * @psalm-return Traversable + * @phpstan-return Traversable */ #[ReturnTypeWillChange] public function getIterator() @@ -348,12 +346,12 @@ public function getIterator() /** * {@inheritDoc} * - * @psalm-param Closure(T):U $func + * @phpstan-param Closure(T):U $func * * @return static - * @psalm-return static + * @phpstan-return static * - * @psalm-template U + * @phpstan-template U */ public function map(Closure $func) { @@ -371,10 +369,10 @@ public function reduce(Closure $func, $initial = null) /** * {@inheritDoc} * - * @psalm-param Closure(T, TKey):bool $p + * @phpstan-param Closure(T, TKey):bool $p * * @return static - * @psalm-return static + * @phpstan-return static */ public function filter(Closure $p) { @@ -455,7 +453,7 @@ public function slice(int $offset, int|null $length = null) return array_slice($this->elements, $offset, $length, true); } - /** @psalm-return Collection&Selectable */ + /** @phpstan-return Collection&Selectable */ public function matching(Criteria $criteria) { $expr = $criteria->getWhereExpression(); diff --git a/src/Collection.php b/src/Collection.php index c3c62aa5..265d9d8e 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -24,8 +24,8 @@ * position unless you explicitly positioned it before. Prefer iteration with * external iterators. * - * @psalm-template TKey of array-key - * @psalm-template T + * @phpstan-template TKey of array-key + * @phpstan-template T * @template-extends ReadableCollection * @template-extends ArrayAccess */ @@ -35,7 +35,7 @@ interface Collection extends ReadableCollection, ArrayAccess * Adds an element at the end of the collection. * * @param mixed $element The element to add. - * @psalm-param T $element + * @phpstan-param T $element * * @return void we will require a native return type declaration in 3.0 */ @@ -52,10 +52,10 @@ public function clear(); * Removes the element at the specified index from the collection. * * @param string|int $key The key/index of the element to remove. - * @psalm-param TKey $key + * @phpstan-param TKey $key * * @return mixed The removed element or NULL, if the collection did not contain the element. - * @psalm-return T|null + * @phpstan-return T|null */ public function remove(string|int $key); @@ -63,7 +63,7 @@ public function remove(string|int $key); * Removes the specified element from the collection, if it is found. * * @param mixed $element The element to remove. - * @psalm-param T $element + * @phpstan-param T $element * * @return bool TRUE if this collection contained the specified element, FALSE otherwise. */ @@ -74,8 +74,8 @@ public function removeElement(mixed $element); * * @param string|int $key The key/index of the element to set. * @param mixed $value The element to set. - * @psalm-param TKey $key - * @psalm-param T $value + * @phpstan-param TKey $key + * @phpstan-param T $value * * @return void */ @@ -84,34 +84,34 @@ public function set(string|int $key, mixed $value); /** * {@inheritDoc} * - * @psalm-param Closure(T):U $func + * @phpstan-param Closure(T):U $func * * @return Collection - * @psalm-return Collection + * @phpstan-return Collection * - * @psalm-template U + * @phpstan-template U */ public function map(Closure $func); /** * {@inheritDoc} * - * @psalm-param Closure(T, TKey):bool $p + * @phpstan-param Closure(T, TKey):bool $p * * @return Collection A collection with the results of the filter operation. - * @psalm-return Collection + * @phpstan-return Collection */ public function filter(Closure $p); /** * {@inheritDoc} * - * @psalm-param Closure(TKey, T):bool $p + * @phpstan-param Closure(TKey, T):bool $p * * @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} + * @phpstan-return array{0: Collection, 1: Collection} */ public function partition(Closure $p); } diff --git a/src/Criteria.php b/src/Criteria.php index 4c8a0a7a..7e690b4f 100644 --- a/src/Criteria.php +++ b/src/Criteria.php @@ -15,7 +15,7 @@ /** * Criteria for filtering Selectable collections. * - * @psalm-consistent-constructor + * @phpstan-consistent-constructor */ class Criteria { diff --git a/src/ReadableCollection.php b/src/ReadableCollection.php index a8dbd43f..d895ab41 100644 --- a/src/ReadableCollection.php +++ b/src/ReadableCollection.php @@ -9,7 +9,7 @@ use IteratorAggregate; /** - * @psalm-template TKey of array-key + * @phpstan-template TKey of array-key * @template-covariant T * @template-extends IteratorAggregate */ @@ -20,10 +20,10 @@ interface ReadableCollection extends Countable, IteratorAggregate * This is an O(n) operation, where n is the size of the collection. * * @param mixed $element The element to search for. - * @psalm-param TMaybeContained $element + * @phpstan-param TMaybeContained $element * * @return bool TRUE if the collection contains the element, FALSE otherwise. - * @psalm-return (TMaybeContained is T ? bool : false) + * @phpstan-return (TMaybeContained is T ? bool : false) * * @template TMaybeContained */ @@ -40,7 +40,7 @@ public function isEmpty(); * Checks whether the collection contains an element with the specified key/index. * * @param string|int $key The key/index to check for. - * @psalm-param TKey $key + * @phpstan-param TKey $key * * @return bool TRUE if the collection contains an element with the specified key/index, * FALSE otherwise. @@ -51,10 +51,10 @@ public function containsKey(string|int $key); * Gets the element at the specified key/index. * * @param string|int $key The key/index of the element to retrieve. - * @psalm-param TKey $key + * @phpstan-param TKey $key * * @return mixed - * @psalm-return T|null + * @phpstan-return T|null */ public function get(string|int $key); @@ -63,7 +63,7 @@ public function get(string|int $key); * * @return int[]|string[] The keys/indices of the collection, in the order of the corresponding * elements in the collection. - * @psalm-return list + * @phpstan-return list */ public function getKeys(); @@ -72,7 +72,7 @@ public function getKeys(); * * @return mixed[] The values of all elements in the collection, in the * order they appear in the collection. - * @psalm-return list + * @phpstan-return list */ public function getValues(); @@ -80,7 +80,7 @@ public function getValues(); * Gets a native PHP array representation of the collection. * * @return mixed[] - * @psalm-return array + * @phpstan-return array */ public function toArray(); @@ -88,7 +88,7 @@ public function toArray(); * Sets the internal iterator to the first element in the collection and returns this element. * * @return mixed - * @psalm-return T|false + * @phpstan-return T|false */ public function first(); @@ -96,7 +96,7 @@ public function first(); * Sets the internal iterator to the last element in the collection and returns this element. * * @return mixed - * @psalm-return T|false + * @phpstan-return T|false */ public function last(); @@ -104,7 +104,7 @@ public function last(); * Gets the key/index of the element at the current iterator position. * * @return int|string|null - * @psalm-return TKey|null + * @phpstan-return TKey|null */ public function key(); @@ -112,7 +112,7 @@ public function key(); * Gets the element of the collection at the current iterator position. * * @return mixed - * @psalm-return T|false + * @phpstan-return T|false */ public function current(); @@ -120,7 +120,7 @@ public function current(); * Moves the internal iterator position to the next element and returns this element. * * @return mixed - * @psalm-return T|false + * @phpstan-return T|false */ public function next(); @@ -135,7 +135,7 @@ public function next(); * @param int|null $length The maximum number of elements to return, or null for no limit. * * @return mixed[] - * @psalm-return array + * @phpstan-return array */ public function slice(int $offset, int|null $length = null); @@ -143,7 +143,7 @@ public function slice(int $offset, int|null $length = null); * Tests for the existence of an element that satisfies the given predicate. * * @param Closure $p The predicate. - * @psalm-param Closure(TKey, T):bool $p + * @phpstan-param Closure(TKey, T):bool $p * * @return bool TRUE if the predicate is TRUE for at least one element, FALSE otherwise. */ @@ -154,10 +154,10 @@ public function exists(Closure $p); * The order of the elements is preserved. * * @param Closure $p The predicate used for filtering. - * @psalm-param Closure(T, TKey):bool $p + * @phpstan-param Closure(T, TKey):bool $p * * @return ReadableCollection A collection with the results of the filter operation. - * @psalm-return ReadableCollection + * @phpstan-return ReadableCollection */ public function filter(Closure $p); @@ -165,12 +165,12 @@ public function filter(Closure $p); * Applies the given function to each element in the collection and returns * a new collection with the elements returned by the function. * - * @psalm-param Closure(T):U $func + * @phpstan-param Closure(T):U $func * * @return ReadableCollection - * @psalm-return ReadableCollection + * @phpstan-return ReadableCollection * - * @psalm-template U + * @phpstan-template U */ public function map(Closure $func); @@ -179,12 +179,12 @@ public function map(Closure $func); * Keys are preserved in the resulting collections. * * @param Closure $p The predicate on which to partition. - * @psalm-param Closure(TKey, T):bool $p + * @phpstan-param Closure(TKey, T):bool $p * * @return ReadableCollection[] 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: ReadableCollection, 1: ReadableCollection} + * @phpstan-return array{0: ReadableCollection, 1: ReadableCollection} */ public function partition(Closure $p); @@ -192,7 +192,7 @@ public function partition(Closure $p); * Tests whether the given predicate p holds for all elements of this collection. * * @param Closure $p The predicate. - * @psalm-param Closure(TKey, T):bool $p + * @phpstan-param Closure(TKey, T):bool $p * * @return bool TRUE, if the predicate yields TRUE for all elements, FALSE otherwise. */ @@ -204,10 +204,10 @@ public function forAll(Closure $p); * For objects this means reference equality. * * @param mixed $element The element to search for. - * @psalm-param TMaybeContained $element + * @phpstan-param TMaybeContained $element * * @return int|string|bool The key/index of the element or FALSE if the element was not found. - * @psalm-return (TMaybeContained is T ? TKey|false : false) + * @phpstan-return (TMaybeContained is T ? TKey|false : false) * * @template TMaybeContained */ @@ -217,11 +217,11 @@ public function indexOf(mixed $element); * Returns the first element of this collection that satisfies the predicate p. * * @param Closure $p The predicate. - * @psalm-param Closure(TKey, T):bool $p + * @phpstan-param Closure(TKey, T):bool $p * * @return mixed The first element respecting the predicate, * null if no element respects the predicate. - * @psalm-return T|null + * @phpstan-return T|null */ public function findFirst(Closure $p); @@ -229,14 +229,14 @@ public function findFirst(Closure $p); * Applies iteratively the given function to each element in the collection, * so as to reduce the collection to a single value. * - * @psalm-param Closure(TReturn|TInitial, T):TReturn $func - * @psalm-param TInitial $initial + * @phpstan-param Closure(TReturn|TInitial, T):TReturn $func + * @phpstan-param TInitial $initial * * @return mixed - * @psalm-return TReturn|TInitial + * @phpstan-return TReturn|TInitial * - * @psalm-template TReturn - * @psalm-template TInitial + * @phpstan-template TReturn + * @phpstan-template TInitial */ public function reduce(Closure $func, mixed $initial = null); } diff --git a/src/Selectable.php b/src/Selectable.php index 5fa87cba..eb11c936 100644 --- a/src/Selectable.php +++ b/src/Selectable.php @@ -16,8 +16,8 @@ * this API can implement efficient database access without having to ask the * EntityManager or Repositories. * - * @psalm-template TKey as array-key - * @psalm-template-covariant T + * @phpstan-template TKey as array-key + * @phpstan-template-covariant T */ interface Selectable { @@ -26,7 +26,7 @@ interface Selectable * returns a new collection containing these elements and preserved keys. * * @return ReadableCollection&Selectable - * @psalm-return ReadableCollection&Selectable + * @phpstan-return ReadableCollection&Selectable */ public function matching(Criteria $criteria); } diff --git a/tests/AbstractLazyCollectionTest.php b/tests/AbstractLazyCollectionTest.php index 8f38e238..069002e0 100644 --- a/tests/AbstractLazyCollectionTest.php +++ b/tests/AbstractLazyCollectionTest.php @@ -23,7 +23,7 @@ protected function setUp(): void $this->collection = new LazyArrayCollection(new ArrayCollection()); } - /** @psalm-param mixed[] $elements */ + /** @phpstan-param mixed[] $elements */ private function buildCollection(array $elements): LazyArrayCollection { return new LazyArrayCollection(new ArrayCollection($elements)); diff --git a/tests/ArrayCollectionTestCase.php b/tests/ArrayCollectionTestCase.php index 260fe724..d77bbab7 100644 --- a/tests/ArrayCollectionTestCase.php +++ b/tests/ArrayCollectionTestCase.php @@ -183,7 +183,7 @@ public function testIterator(array $elements): void self::assertEquals(count($elements), $iterations, 'Number of iterations not match'); } - /** @psalm-return array */ + /** @phpstan-return array */ public static function provideDifferentElements(): array { return [ diff --git a/tests/StaticAnalysis/CustomCollection.php b/tests/StaticAnalysis/CustomCollection.php index 1aaee7e7..69ce0d6b 100644 --- a/tests/StaticAnalysis/CustomCollection.php +++ b/tests/StaticAnalysis/CustomCollection.php @@ -25,7 +25,7 @@ public function __construct(ArrayCollection $arrayCollection) } /** - * @psalm-param Closure(T, TKey):bool $p + * @phpstan-param Closure(T, TKey):bool $p * * @return Collection */ @@ -35,9 +35,9 @@ public function filter(Closure $p) } /** - * @psalm-param Closure(TKey, T):bool $p + * @phpstan-param Closure(TKey, T):bool $p * - * @psalm-return array{0: Collection, 1: Collection} + * @phpstan-return array{0: Collection, 1: Collection} */ public function partition(Closure $p) {