Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bfe2cff
Update annotation for IDE autocomplete
rochamarcelo Aug 9, 2025
1916d36
Update annotation for IDE autocomplete
rochamarcelo Aug 9, 2025
22ac41c
Update annotation for IDE autocomplete
rochamarcelo Aug 9, 2025
60fd670
fix phpstan issues withcorrect annotations for IDE autocomplete
rochamarcelo Aug 9, 2025
df82801
Use generic return for collection inteface
rochamarcelo Aug 9, 2025
eabd4b6
Re-added extends to avoid PHPStan error
rochamarcelo Aug 10, 2025
52fc699
Remove phpdoc causing error on IDE
rochamarcelo Aug 11, 2025
68cf18d
Fixing typo
rochamarcelo Aug 11, 2025
804c0e4
Use generic for return types
rochamarcelo Aug 11, 2025
8f8e6b9
Use generic for return types
rochamarcelo Aug 11, 2025
afc0d0d
IteratoIterator extends
rochamarcelo Aug 11, 2025
ae1b260
Fix phpstan issues
rochamarcelo Aug 16, 2025
eb07502
Fix phpstan issues
rochamarcelo Aug 16, 2025
c2f62df
Ignore phpstan error generics.interfaceConflict
rochamarcelo Aug 16, 2025
3259b74
Fix phpstan issues
rochamarcelo Aug 16, 2025
129fc8e
Use array instead of list, lists has caused issues before
rochamarcelo Aug 21, 2025
16f0264
Moved conditional return to phpstan specific annotation
rochamarcelo Aug 21, 2025
02669a6
Annotations must be compatible with Traversable
rochamarcelo Aug 24, 2025
675dab3
Annotations must be compatible with Traversable. Improved phpdoc with…
rochamarcelo Aug 24, 2025
9ab4c4c
PHPStan fixes
rochamarcelo Aug 24, 2025
de102d4
Merge branch '5.x' into generic-types-collection
rochamarcelo Sep 1, 2025
f26db02
Fix git conflicts
rochamarcelo Sep 1, 2025
1345baf
PHPCS fix
rochamarcelo Sep 3, 2025
4c73331
PHPCS fixes
rochamarcelo Sep 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
246 changes: 246 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ parameters:
count: 1
path: src/Cache/Engine/MemcachedEngine.php

-
message: '#^Parameter \#1 \$value of function count expects array\|Countable, TValue\|false given\.$#'
identifier: argument.type
count: 1
path: src/Collection/Collection.php

-
message: '#^Unsafe usage of new static\(\)\.$#'
identifier: new.static
Expand Down Expand Up @@ -114,6 +120,126 @@ parameters:
count: 1
path: src/Datasource/QueryInterface.php

-
message: '#^Class Cake\\Collection\\Collection specifies template type TKey of interface Cake\\Collection\\CollectionInterface as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Class Cake\\Collection\\Collection specifies template type TKey of interface Iterator as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Class Cake\\Collection\\Collection specifies template type TKey of interface Traversable as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Class Cake\\Collection\\Collection specifies template type TValue of interface Cake\\Collection\\CollectionInterface as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Class Cake\\Collection\\Collection specifies template type TValue of interface Iterator as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Class Cake\\Collection\\Collection specifies template type TValue of interface Traversable as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Class IteratorIterator specifies template type TKey of interface Iterator as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 2
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Class IteratorIterator specifies template type TKey of interface Traversable as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 2
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Class IteratorIterator specifies template type TValue of interface Iterator as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 2
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Class IteratorIterator specifies template type TValue of interface Traversable as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 2
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Interface Cake\\Collection\\CollectionInterface specifies template type TKey of interface Iterator as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Interface Cake\\Collection\\CollectionInterface specifies template type TKey of interface Traversable as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Interface Cake\\Collection\\CollectionInterface specifies template type TValue of interface Iterator as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Interface Cake\\Collection\\CollectionInterface specifies template type TValue of interface Traversable as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Interface Iterator specifies template type TKey of interface Traversable as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 7
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Interface Iterator specifies template type TValue of interface Traversable as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 7
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Interface OuterIterator specifies template type TKey of interface Iterator as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 3
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Interface OuterIterator specifies template type TKey of interface Traversable as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 3
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Interface OuterIterator specifies template type TValue of interface Iterator as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 3
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Interface OuterIterator specifies template type TValue of interface Traversable as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 3
path: src/Datasource/ResultSetDecorator.php

-
message: '#^Constructor of class Cake\\Error\\Renderer\\ConsoleExceptionRenderer has an unused parameter \$request\.$#'
identifier: constructor.unusedParameter
Expand Down Expand Up @@ -258,6 +384,126 @@ parameters:
count: 1
path: src/ORM/Query/SelectQuery.php

-
message: '#^Class Cake\\Collection\\Collection specifies template type TKey of interface Cake\\Collection\\CollectionInterface as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/ORM/ResultSet.php

-
message: '#^Class Cake\\Collection\\Collection specifies template type TKey of interface Iterator as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/ORM/ResultSet.php

-
message: '#^Class Cake\\Collection\\Collection specifies template type TKey of interface Traversable as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/ORM/ResultSet.php

-
message: '#^Class Cake\\Collection\\Collection specifies template type TValue of interface Cake\\Collection\\CollectionInterface as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/ORM/ResultSet.php

-
message: '#^Class Cake\\Collection\\Collection specifies template type TValue of interface Iterator as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/ORM/ResultSet.php

-
message: '#^Class Cake\\Collection\\Collection specifies template type TValue of interface Traversable as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/ORM/ResultSet.php

-
message: '#^Class IteratorIterator specifies template type TKey of interface Iterator as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 2
path: src/ORM/ResultSet.php

-
message: '#^Class IteratorIterator specifies template type TKey of interface Traversable as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 2
path: src/ORM/ResultSet.php

-
message: '#^Class IteratorIterator specifies template type TValue of interface Iterator as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 2
path: src/ORM/ResultSet.php

-
message: '#^Class IteratorIterator specifies template type TValue of interface Traversable as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 2
path: src/ORM/ResultSet.php

-
message: '#^Interface Cake\\Collection\\CollectionInterface specifies template type TKey of interface Iterator as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/ORM/ResultSet.php

-
message: '#^Interface Cake\\Collection\\CollectionInterface specifies template type TKey of interface Traversable as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/ORM/ResultSet.php

-
message: '#^Interface Cake\\Collection\\CollectionInterface specifies template type TValue of interface Iterator as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/ORM/ResultSet.php

-
message: '#^Interface Cake\\Collection\\CollectionInterface specifies template type TValue of interface Traversable as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 1
path: src/ORM/ResultSet.php

-
message: '#^Interface Iterator specifies template type TKey of interface Traversable as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 7
path: src/ORM/ResultSet.php

-
message: '#^Interface Iterator specifies template type TValue of interface Traversable as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 7
path: src/ORM/ResultSet.php

-
message: '#^Interface OuterIterator specifies template type TKey of interface Iterator as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 3
path: src/ORM/ResultSet.php

-
message: '#^Interface OuterIterator specifies template type TKey of interface Traversable as TKey but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 3
path: src/ORM/ResultSet.php

-
message: '#^Interface OuterIterator specifies template type TValue of interface Iterator as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 3
path: src/ORM/ResultSet.php

-
message: '#^Interface OuterIterator specifies template type TValue of interface Traversable as TValue but it''s already specified as mixed\.$#'
identifier: generics.interfaceConflict
count: 3
path: src/ORM/ResultSet.php

-
message: '#^Call to function method_exists\(\) with Cake\\Datasource\\EntityInterface and ''patch'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
Expand Down
5 changes: 4 additions & 1 deletion src/Collection/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
* A collection is an immutable list of elements with a handful of functions to
* iterate, group, transform and extract information from it.
*
* @template-extends \IteratorIterator<mixed, mixed, \Traversable<mixed>>
* @template TKey
* @template TValue
* @extends \IteratorIterator<TKey, TValue, \Traversable<TKey, TValue>>
* @implements \Cake\Collection\CollectionInterface<TKey, TValue>
*/
class Collection extends IteratorIterator implements CollectionInterface
{
Expand Down
15 changes: 9 additions & 6 deletions src/Collection/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
* list of elements exposing a number of traversing and extracting method for
* generating other collections.
*
* @template-extends \Iterator<mixed>
* @template TKey
* @template-covariant TValue
* @template-extends \Iterator<TKey, TValue>
*/
interface CollectionInterface extends Iterator, JsonSerializable, Countable
{
Expand Down Expand Up @@ -641,21 +643,21 @@ public function match(array $conditions): CollectionInterface;
* a property path as accepted by `Collection::extract`, and the value the
* condition against with each element will be matched
* @see \Cake\Collection\CollectionInterface::match()
* @return mixed
* @return TValue|null
*/
public function firstMatch(array $conditions): mixed;

/**
* Returns the first result in this collection
*
* @return mixed The first value in the collection will be returned.
* @return TValue|null The first value in the collection will be returned.
*/
public function first(): mixed;

/**
* Returns the last result in this collection
*
* @return mixed The last value in the collection will be returned.
* @return TValue|null The last value in the collection will be returned.
*/
public function last(): mixed;

Expand Down Expand Up @@ -802,15 +804,16 @@ public function insert(string $path, mixed $values): CollectionInterface;
* collection as the array keys. Keep in mind that it is valid for iterators
* to return the same key for different elements, setting this value to false
* can help getting all items if keys are not important in the result.
* @return array
* @phpstan-return ($keepKeys is true ? array<TKey, TValue> : array<int, TValue>)
* @return array<TKey, TValue>|array<int, TValue>
*/
public function toArray(bool $keepKeys = true): array;

/**
* Returns an numerically-indexed array representation of the results.
* This is equivalent to calling `toArray(false)`
*
* @return array
* @return array<int, TValue>
*/
public function toList(): array;

Expand Down
6 changes: 4 additions & 2 deletions src/Datasource/Paging/PaginatedInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
/**
* This interface describes the methods for pagination instance.
*
* @template-extends \Traversable<mixed>
* @template TKey
* @template-covariant TValue
* @template-extends \Traversable<TKey, TValue>
* @method array<mixed> toArray() Get the paginated items as an array
*/
interface PaginatedInterface extends Countable, Traversable
Expand Down Expand Up @@ -72,7 +74,7 @@ public function hasNextPage(): bool;
/**
* Get paginated items.
*
* @return iterable
* @return iterable<TKey, TValue>
*/
public function items(): iterable;

Expand Down
Loading
Loading