Skip to content

Commit 3e95402

Browse files
Mark typehinted variables as nullable if they have null defaults, inline with PHP 8.4 deprecations
1 parent e88173f commit 3e95402

8 files changed

Lines changed: 28 additions & 28 deletions

src/Arrayy.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ public static function createFromObjectVars($object): self
19411941
* @phpstan-return static<int,string>
19421942
* @psalm-mutation-free
19431943
*/
1944-
public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self
1944+
public static function createFromString(string $str, ?string $delimiter = null, ?string $regEx = null): self
19451945
{
19461946
if ($regEx) {
19471947
\preg_match_all($regEx, $str, $array);
@@ -2648,7 +2648,7 @@ public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH)
26482648
public function filterBy(
26492649
string $property,
26502650
$value,
2651-
string $comparisonOp = null
2651+
?string $comparisonOp = null
26522652
): self {
26532653
if (!$comparisonOp) {
26542654
$comparisonOp = \is_array($value) ? 'contains' : 'eq';
@@ -2834,7 +2834,7 @@ public function firstKey()
28342834
* @phpstan-return static<TKey,T>
28352835
* @psalm-mutation-free
28362836
*/
2837-
public function firstsImmutable(int $number = null): self
2837+
public function firstsImmutable(?int $number = null): self
28382838
{
28392839
$arrayTmp = $this->toArray();
28402840

@@ -2863,7 +2863,7 @@ public function firstsImmutable(int $number = null): self
28632863
* @phpstan-return static<array-key,TKey>
28642864
* @psalm-mutation-free
28652865
*/
2866-
public function firstsKeys(int $number = null): self
2866+
public function firstsKeys(?int $number = null): self
28672867
{
28682868
$arrayTmp = $this->keys()->toArray();
28692869

@@ -2895,7 +2895,7 @@ public function firstsKeys(int $number = null): self
28952895
*
28962896
* @phpstan-return ($number is null ? static<int,T> : static<TKey,T>)
28972897
*/
2898-
public function firstsMutable(int $number = null): self
2898+
public function firstsMutable(?int $number = null): self
28992899
{
29002900
$this->generatorToArray();
29012901

@@ -2972,7 +2972,7 @@ public function flip(): self
29722972
public function get(
29732973
$key = null,
29742974
$fallback = null,
2975-
array $array = null,
2975+
?array $array = null,
29762976
bool $useByReference = false
29772977
) {
29782978
if ($array === null && $key === null) {
@@ -4265,7 +4265,7 @@ public function lastKey()
42654265
* @phpstan-return static<TKey,T>
42664266
* @psalm-mutation-free
42674267
*/
4268-
public function lastsImmutable(int $number = null): self
4268+
public function lastsImmutable(?int $number = null): self
42694269
{
42704270
if ($this->isEmpty()) {
42714271
return static::create(
@@ -4310,7 +4310,7 @@ public function lastsImmutable(int $number = null): self
43104310
*
43114311
* @phpstan-return static<TKey,T>
43124312
*/
4313-
public function lastsMutable(int $number = null): self
4313+
public function lastsMutable(?int $number = null): self
43144314
{
43154315
if ($this->isEmpty()) {
43164316
return $this;
@@ -4724,7 +4724,7 @@ public function mostUsedValue()
47244724
* @phpstan-return static<array-key,T>
47254725
* @psalm-mutation-free
47264726
*/
4727-
public function mostUsedValues(int $number = null): self
4727+
public function mostUsedValues(?int $number = null): self
47284728
{
47294729
return $this->countValues()->arsortImmutable()->firstsKeys($number);
47304730
}
@@ -5230,7 +5230,7 @@ public function push(...$args)
52305230
*
52315231
* @phpstan-return static<array-key,T>
52325232
*/
5233-
public function randomImmutable(int $number = null): self
5233+
public function randomImmutable(?int $number = null): self
52345234
{
52355235
$this->generatorToArray();
52365236

@@ -5347,7 +5347,7 @@ public function randomKeys(int $number): self
53475347
*
53485348
* @phpstan-return static<TKey,T>
53495349
*/
5350-
public function randomMutable(int $number = null): self
5350+
public function randomMutable(?int $number = null): self
53515351
{
53525352
$this->generatorToArray();
53535353

@@ -5429,7 +5429,7 @@ public function randomValues(int $number): self
54295429
* @phpstan-param array<(int&T)|(string&T),int> $array
54305430
* @phpstan-return static<array-key,T>
54315431
*/
5432-
public function randomWeighted(array $array, int $number = null): self
5432+
public function randomWeighted(array $array, ?int $number = null): self
54335433
{
54345434
// init
54355435
$options = [];
@@ -6248,7 +6248,7 @@ public function shift()
62486248
* @phpstan-param array<TKey,T> $array
62496249
* @phpstan-return static<TKey,T>
62506250
*/
6251-
public function shuffle(bool $secure = false, array $array = null): self
6251+
public function shuffle(bool $secure = false, ?array $array = null): self
62526252
{
62536253
if ($array === null) {
62546254
$array = $this->toArray(false);
@@ -6454,7 +6454,7 @@ public function sizeRecursive(): int
64546454
* @phpstan-return static<array-key,T>
64556455
* @psalm-mutation-free
64566456
*/
6457-
public function slice(int $offset, int $length = null, bool $preserveKeys = false)
6457+
public function slice(int $offset, ?int $length = null, bool $preserveKeys = false)
64586458
{
64596459
return static::create(
64606460
\array_slice(
@@ -6719,7 +6719,7 @@ static function ($value) use ($sorter) {
67196719
* @phpstan-return static<TKey,T>
67206720
* @psalm-mutation-free
67216721
*/
6722-
public function splice(int $offset, int $length = null, $replacement = []): self
6722+
public function splice(int $offset, ?int $length = null, $replacement = []): self
67236723
{
67246724
$tmpArray = $this->toArray();
67256725

@@ -6967,7 +6967,7 @@ public function toJson(int $options = 0, int $depth = 512): string
69676967
*
69686968
* @phpstan-return static<int, static<TKey,T>>
69696969
*/
6970-
public function toPermutation(array $items = null, array $helper = []): self
6970+
public function toPermutation(?array $items = null, array $helper = []): self
69716971
{
69726972
// init
69736973
$return = [];

src/ArrayyRewindableExtendedGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ArrayyRewindableExtendedGenerator extends ArrayyRewindableGenerator
1515
{
1616
public function __construct(
1717
callable $generatorConstructionFunction,
18-
callable $onRewind = null,
18+
?callable $onRewind = null,
1919
string $class = ''
2020
) {
2121
parent::__construct(

src/ArrayyRewindableGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ArrayyRewindableGenerator extends \ArrayIterator
4949
*/
5050
public function __construct(
5151
callable $generatorConstructionFunction,
52-
callable $onRewind = null,
52+
?callable $onRewind = null,
5353
string $class = ''
5454
) {
5555
$this->class = $class;

src/Collection/Collection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ class Collection extends AbstractCollection
102102
*/
103103
public function __construct(
104104
$data = [],
105-
string $iteratorClass = null,
106-
bool $checkPropertiesInConstructor = null,
107-
TypeInterface $type = null
105+
?string $iteratorClass = null,
106+
?bool $checkPropertiesInConstructor = null,
107+
?TypeInterface $type = null
108108
) {
109109
// fallback
110110
if ($iteratorClass === null) {

src/Collection/CollectionInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ public function set($key, $value);
496496
*
497497
* @phpstan-return CollectionInterface<array-key|TKey,T>
498498
*/
499-
public function slice(int $offset, int $length = null, bool $preserveKeys = false);
499+
public function slice(int $offset, ?int $length = null, bool $preserveKeys = false);
500500

501501
/**
502502
* Gets a native PHP array representation of the collection.

src/StaticArrayy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static function __callStatic(string $name, $arguments)
7575
* @psalm-suppress InvalidReturnStatement - why?
7676
* @psalm-suppress InvalidReturnType - why?
7777
*/
78-
public static function range(int $base, int $stop = null, int $step = 1): Arrayy
78+
public static function range(int $base, ?int $stop = null, int $step = 1): Arrayy
7979
{
8080
if ($stop !== null) {
8181
$start = $base;

src/Type/InstanceCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ final class InstanceCollection extends Collection implements TypeInterface
2626
*/
2727
public function __construct(
2828
array $data = [],
29-
string $iteratorClass = null,
30-
bool $checkPropertiesInConstructor = null,
29+
?string $iteratorClass = null,
30+
?bool $checkPropertiesInConstructor = null,
3131
$className = null
3232
) {
3333
// fallback

src/Type/InstancesCollection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ final class InstancesCollection extends Collection implements TypeInterface
2626
*/
2727
public function __construct(
2828
array $data = [],
29-
string $iteratorClass = null,
30-
bool $checkPropertiesInConstructor = null,
31-
array $classNames = null
29+
?string $iteratorClass = null,
30+
?bool $checkPropertiesInConstructor = null,
31+
?array $classNames = null
3232
) {
3333
// fallback
3434
if ($iteratorClass === null) {

0 commit comments

Comments
 (0)