Skip to content

Commit 5f005af

Browse files
committed
fix list methods so psalm doesn't see it as list<never>
1 parent 79155f9 commit 5f005af

3 files changed

Lines changed: 40 additions & 30 deletions

File tree

src/Assert.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,11 +1986,9 @@ public static function countBetween(mixed $array, mixed $min, mixed $max, string
19861986
/**
19871987
* @psalm-pure
19881988
*
1989-
* @psalm-assert list<T> $array
1989+
* @psalm-assert list<mixed> $array
19901990
*
1991-
* @psalm-return list<T>
1992-
*
1993-
* @template T
1991+
* @psalm-return list<mixed>
19941992
*
19951993
* @throws InvalidArgumentException
19961994
*/
@@ -2008,11 +2006,9 @@ public static function isList(mixed $array, string $message = ''): array
20082006
/**
20092007
* @psalm-pure
20102008
*
2011-
* @psalm-assert non-empty-list<T> $array
2009+
* @psalm-assert non-empty-list<mixed> $array
20122010
*
2013-
* @psalm-return non-empty-list<T>
2014-
*
2015-
* @template T
2011+
* @psalm-return non-empty-list<mixed>
20162012
*
20172013
* @throws InvalidArgumentException
20182014
*/

src/Mixin.php

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4754,27 +4754,29 @@ public static function allNullOrCountBetween(mixed $array, mixed $min, mixed $ma
47544754
/**
47554755
* @psalm-pure
47564756
*
4757-
* @psalm-assert list<T>|null $array
4757+
* @psalm-assert list<mixed>|null $array
47584758
*
4759-
* @template T
4760-
* @return list<T>|null
4759+
* @return list<mixed>|null
47614760
*
47624761
* @throws InvalidArgumentException
47634762
*/
4764-
public static function nullOrIsList(mixed $array, string $message = ''): mixed
4763+
public static function nullOrIsList(mixed $array, string $message = ''): ?array
47654764
{
4766-
null === $array || static::isList($array, $message);
4765+
if($array === null) {
4766+
return null;
4767+
}
4768+
4769+
static::isList($array, $message);
47674770

47684771
return $array;
47694772
}
47704773

47714774
/**
47724775
* @psalm-pure
47734776
*
4774-
* @psalm-assert iterable<list<T>> $array
4777+
* @psalm-assert iterable<list<mixed>> $array
47754778
*
4776-
* @template T
4777-
* @return iterable<list<T>>
4779+
* @return iterable<list<mixed>>
47784780
*
47794781
* @throws InvalidArgumentException
47804782
*/
@@ -4792,10 +4794,9 @@ public static function allIsList(mixed $array, string $message = ''): mixed
47924794
/**
47934795
* @psalm-pure
47944796
*
4795-
* @psalm-assert iterable<list<T>|null> $array
4797+
* @psalm-assert iterable<list<mixed>|null> $array
47964798
*
4797-
* @template T
4798-
* @return iterable<list<T>|null>
4799+
* @return iterable<list<mixed>|null>
47994800
*
48004801
* @throws InvalidArgumentException
48014802
*/
@@ -4813,27 +4814,29 @@ public static function allNullOrIsList(mixed $array, string $message = ''): mixe
48134814
/**
48144815
* @psalm-pure
48154816
*
4816-
* @psalm-assert non-empty-list<T>|null $array
4817+
* @psalm-assert non-empty-list|null $array
48174818
*
4818-
* @template T
4819-
* @return non-empty-list<T>|null
4819+
* @return non-empty-list|null
48204820
*
48214821
* @throws InvalidArgumentException
48224822
*/
4823-
public static function nullOrIsNonEmptyList(mixed $array, string $message = ''): mixed
4823+
public static function nullOrIsNonEmptyList(mixed $array, string $message = ''): ?array
48244824
{
4825-
null === $array || static::isNonEmptyList($array, $message);
4825+
if($array === null) {
4826+
return null;
4827+
}
4828+
4829+
static::isNonEmptyList($array, $message);
48264830

48274831
return $array;
48284832
}
48294833

48304834
/**
48314835
* @psalm-pure
48324836
*
4833-
* @psalm-assert iterable<non-empty-list<T>> $array
4837+
* @psalm-assert iterable<non-empty-list> $array
48344838
*
4835-
* @template T
4836-
* @return iterable<non-empty-list<T>>
4839+
* @return iterable<non-empty-list>
48374840
*
48384841
* @throws InvalidArgumentException
48394842
*/
@@ -4851,10 +4854,9 @@ public static function allIsNonEmptyList(mixed $array, string $message = ''): mi
48514854
/**
48524855
* @psalm-pure
48534856
*
4854-
* @psalm-assert iterable<non-empty-list<T>|null> $array
4857+
* @psalm-assert iterable<non-empty-list|null> $array
48554858
*
4856-
* @template T
4857-
* @return iterable<non-empty-list<T>|null>
4859+
* @return iterable<non-empty-list|null>
48584860
*
48594861
* @throws InvalidArgumentException
48604862
*/

tests/static-analysis/assert-isNonEmptyList.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ function isNonEmptyList(mixed $value): array
2020
return $value;
2121
}
2222

23+
/**
24+
* @psalm-pure
25+
*/
26+
function isNonEmptyListWithRange(): mixed
27+
{
28+
$value = range(1, 100);
29+
30+
Assert::isNonEmptyList($value);
31+
32+
return $value[0];
33+
}
34+
2335
/**
2436
* @psalm-pure
2537
*

0 commit comments

Comments
 (0)