Improved phpdoc for hyperf/collection (#7022)

This commit is contained in:
Deeka Wong 2024-08-24 22:15:22 +08:00 committed by GitHub
parent a2df3fb500
commit 00309bcdaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 45 additions and 59 deletions

View File

@ -31,33 +31,17 @@ use Traversable;
*
* @template TKey of array-key
* @template TValue
* @template TTimesValue
*
* @implements ArrayAccess<TKey, TValue>
* @implements Enumerable<TKey, TValue>
*
* @property HigherOrderCollectionProxy $average
* @property HigherOrderCollectionProxy $avg
* @property HigherOrderCollectionProxy $contains
* @property HigherOrderCollectionProxy $each
* @property HigherOrderCollectionProxy $every
* @property HigherOrderCollectionProxy $filter
* @property HigherOrderCollectionProxy $first
* @property HigherOrderCollectionProxy $flatMap
* @property HigherOrderCollectionProxy $groupBy
* @property HigherOrderCollectionProxy $keyBy
* @property HigherOrderCollectionProxy $map
* @property HigherOrderCollectionProxy $max
* @property HigherOrderCollectionProxy $min
* @property HigherOrderCollectionProxy $partition
* @property HigherOrderCollectionProxy $reject
* @property HigherOrderCollectionProxy $sortBy
* @property HigherOrderCollectionProxy $sortByDesc
* @property HigherOrderCollectionProxy $sum
* @property HigherOrderCollectionProxy $unique
*/
class Collection implements Enumerable, ArrayAccess
{
/**
* @use EnumeratesValues<TKey, TValue>
*/
use EnumeratesValues;
use Macroable;
/**
@ -69,7 +53,7 @@ class Collection implements Enumerable, ArrayAccess
/**
* Create a new collection.
* @param null|iterable<TKey,TValue>|Jsonable|JsonSerializable $items
* @param null|Arrayable<TKey,TValue>|iterable<TKey,TValue>|Jsonable|JsonSerializable $items
*/
public function __construct($items = [])
{
@ -77,7 +61,7 @@ class Collection implements Enumerable, ArrayAccess
}
/**
* @param null|iterable<TKey,TValue>|Jsonable|JsonSerializable $items
* @param null|Arrayable<TKey,TValue>|iterable<TKey, TValue>|Jsonable|JsonSerializable $items
* @return static<TKey, TValue>
*/
public function fill($items = [])
@ -1013,7 +997,7 @@ class Collection implements Enumerable, ArrayAccess
/**
* Create chunks representing a "sliding window" view of the items in the collection.
*
* @return static<int, TTimesValue>
* @return static<int, static>
*/
public function sliding(int $size = 2, int $step = 1): static
{

View File

@ -13,14 +13,17 @@ declare(strict_types=1);
namespace Hyperf\Collection;
/**
* @mixin Collection
* @template TKey of array-key
* @template TValue
*
* @mixin Enumerable
* @mixin TValue
*/
class HigherOrderCollectionProxy
{
/**
* Create a new proxy instance.
* @param Collection $collection the collection being operated on
* @param Enumerable<TKey, TValue> $collection the collection being operated on
* @param string $method the method being proxied
*/
public function __construct(protected Enumerable $collection, protected string $method)

View File

@ -29,7 +29,6 @@ use Traversable;
/**
* @template TKey of array-key
*
* @template TValue
*
* @implements Enumerable<TKey, TValue>

View File

@ -35,38 +35,37 @@ use function Hyperf\Support\value;
/**
* @template TKey of array-key
* @template TTimesValue
*
* @template TValue
* @property HigherOrderCollectionProxy $average
* @property HigherOrderCollectionProxy $avg
* @property HigherOrderCollectionProxy $contains
* @property HigherOrderCollectionProxy $doesntContain
* @property HigherOrderCollectionProxy $each
* @property HigherOrderCollectionProxy $every
* @property HigherOrderCollectionProxy $filter
* @property HigherOrderCollectionProxy $first
* @property HigherOrderCollectionProxy $flatMap
* @property HigherOrderCollectionProxy $groupBy
* @property HigherOrderCollectionProxy $keyBy
* @property HigherOrderCollectionProxy $map
* @property HigherOrderCollectionProxy $max
* @property HigherOrderCollectionProxy $min
* @property HigherOrderCollectionProxy $partition
* @property HigherOrderCollectionProxy $percentage
* @property HigherOrderCollectionProxy $reject
* @property HigherOrderCollectionProxy $skipUntil
* @property HigherOrderCollectionProxy $skipWhile
* @property HigherOrderCollectionProxy $some
* @property HigherOrderCollectionProxy $sortBy
* @property HigherOrderCollectionProxy $sortByDesc
* @property HigherOrderCollectionProxy $sum
* @property HigherOrderCollectionProxy $takeUntil
* @property HigherOrderCollectionProxy $takeWhile
* @property HigherOrderCollectionProxy $unique
* @property HigherOrderCollectionProxy $unless
* @property HigherOrderCollectionProxy $until
* @property HigherOrderCollectionProxy $when
*
* @property HigherOrderCollectionProxy<TKey, TValue> $average
* @property HigherOrderCollectionProxy<TKey, TValue> $avg
* @property HigherOrderCollectionProxy<TKey, TValue> $contains
* @property HigherOrderCollectionProxy<TKey, TValue> $doesntContain
* @property HigherOrderCollectionProxy<TKey, TValue> $each
* @property HigherOrderCollectionProxy<TKey, TValue> $every
* @property HigherOrderCollectionProxy<TKey, TValue> $filter
* @property HigherOrderCollectionProxy<TKey, TValue> $first
* @property HigherOrderCollectionProxy<TKey, TValue> $flatMap
* @property HigherOrderCollectionProxy<TKey, TValue> $groupBy
* @property HigherOrderCollectionProxy<TKey, TValue> $keyBy
* @property HigherOrderCollectionProxy<TKey, TValue> $map
* @property HigherOrderCollectionProxy<TKey, TValue> $max
* @property HigherOrderCollectionProxy<TKey, TValue> $min
* @property HigherOrderCollectionProxy<TKey, TValue> $partition
* @property HigherOrderCollectionProxy<TKey, TValue> $percentage
* @property HigherOrderCollectionProxy<TKey, TValue> $reject
* @property HigherOrderCollectionProxy<TKey, TValue> $skipUntil
* @property HigherOrderCollectionProxy<TKey, TValue> $skipWhile
* @property HigherOrderCollectionProxy<TKey, TValue> $some
* @property HigherOrderCollectionProxy<TKey, TValue> $sortBy
* @property HigherOrderCollectionProxy<TKey, TValue> $sortByDesc
* @property HigherOrderCollectionProxy<TKey, TValue> $sum
* @property HigherOrderCollectionProxy<TKey, TValue> $takeUntil
* @property HigherOrderCollectionProxy<TKey, TValue> $takeWhile
* @property HigherOrderCollectionProxy<TKey, TValue> $unique
* @property HigherOrderCollectionProxy<TKey, TValue> $unless
* @property HigherOrderCollectionProxy<TKey, TValue> $until
* @property HigherOrderCollectionProxy<TKey, TValue> $when
*/
trait EnumeratesValues
{
@ -194,6 +193,7 @@ trait EnumeratesValues
/**
* Create a new collection by invoking the callback a given amount of times.
* @template TTimesValue
*
* @param null|(callable(int): TTimesValue) $callback
* @return static<int, TTimesValue>

View File

@ -211,7 +211,7 @@ class ComponentTagCompiler
$constructor = (new ReflectionClass($class))->getConstructor();
$parameterNames = $constructor
? collect($constructor->getParameters())->map->getName()->all()
? collect($constructor->getParameters())->map->getName()->all() // @phpstan-ignore method.nonObject
: [];
return collect($attributes)->partition(fn ($value, $key) => in_array(Str::camel($key), $parameterNames))->all();