From 3e95402c8cb79e3476e8912d41a5096f009e7700 Mon Sep 17 00:00:00 2001 From: Olly Cross Date: Thu, 31 Jul 2025 17:03:47 +0100 Subject: [PATCH] Mark typehinted variables as nullable if they have null defaults, inline with PHP 8.4 deprecations --- src/Arrayy.php | 32 +++++++++++------------ src/ArrayyRewindableExtendedGenerator.php | 2 +- src/ArrayyRewindableGenerator.php | 2 +- src/Collection/Collection.php | 6 ++--- src/Collection/CollectionInterface.php | 2 +- src/StaticArrayy.php | 2 +- src/Type/InstanceCollection.php | 4 +-- src/Type/InstancesCollection.php | 6 ++--- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Arrayy.php b/src/Arrayy.php index 6449083..3a6ab0c 100644 --- a/src/Arrayy.php +++ b/src/Arrayy.php @@ -1941,7 +1941,7 @@ public static function createFromObjectVars($object): self * @phpstan-return static * @psalm-mutation-free */ - public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self + public static function createFromString(string $str, ?string $delimiter = null, ?string $regEx = null): self { if ($regEx) { \preg_match_all($regEx, $str, $array); @@ -2648,7 +2648,7 @@ public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) public function filterBy( string $property, $value, - string $comparisonOp = null + ?string $comparisonOp = null ): self { if (!$comparisonOp) { $comparisonOp = \is_array($value) ? 'contains' : 'eq'; @@ -2834,7 +2834,7 @@ public function firstKey() * @phpstan-return static * @psalm-mutation-free */ - public function firstsImmutable(int $number = null): self + public function firstsImmutable(?int $number = null): self { $arrayTmp = $this->toArray(); @@ -2863,7 +2863,7 @@ public function firstsImmutable(int $number = null): self * @phpstan-return static * @psalm-mutation-free */ - public function firstsKeys(int $number = null): self + public function firstsKeys(?int $number = null): self { $arrayTmp = $this->keys()->toArray(); @@ -2895,7 +2895,7 @@ public function firstsKeys(int $number = null): self * * @phpstan-return ($number is null ? static : static) */ - public function firstsMutable(int $number = null): self + public function firstsMutable(?int $number = null): self { $this->generatorToArray(); @@ -2972,7 +2972,7 @@ public function flip(): self public function get( $key = null, $fallback = null, - array $array = null, + ?array $array = null, bool $useByReference = false ) { if ($array === null && $key === null) { @@ -4265,7 +4265,7 @@ public function lastKey() * @phpstan-return static * @psalm-mutation-free */ - public function lastsImmutable(int $number = null): self + public function lastsImmutable(?int $number = null): self { if ($this->isEmpty()) { return static::create( @@ -4310,7 +4310,7 @@ public function lastsImmutable(int $number = null): self * * @phpstan-return static */ - public function lastsMutable(int $number = null): self + public function lastsMutable(?int $number = null): self { if ($this->isEmpty()) { return $this; @@ -4724,7 +4724,7 @@ public function mostUsedValue() * @phpstan-return static * @psalm-mutation-free */ - public function mostUsedValues(int $number = null): self + public function mostUsedValues(?int $number = null): self { return $this->countValues()->arsortImmutable()->firstsKeys($number); } @@ -5230,7 +5230,7 @@ public function push(...$args) * * @phpstan-return static */ - public function randomImmutable(int $number = null): self + public function randomImmutable(?int $number = null): self { $this->generatorToArray(); @@ -5347,7 +5347,7 @@ public function randomKeys(int $number): self * * @phpstan-return static */ - public function randomMutable(int $number = null): self + public function randomMutable(?int $number = null): self { $this->generatorToArray(); @@ -5429,7 +5429,7 @@ public function randomValues(int $number): self * @phpstan-param array<(int&T)|(string&T),int> $array * @phpstan-return static */ - public function randomWeighted(array $array, int $number = null): self + public function randomWeighted(array $array, ?int $number = null): self { // init $options = []; @@ -6248,7 +6248,7 @@ public function shift() * @phpstan-param array $array * @phpstan-return static */ - public function shuffle(bool $secure = false, array $array = null): self + public function shuffle(bool $secure = false, ?array $array = null): self { if ($array === null) { $array = $this->toArray(false); @@ -6454,7 +6454,7 @@ public function sizeRecursive(): int * @phpstan-return static * @psalm-mutation-free */ - public function slice(int $offset, int $length = null, bool $preserveKeys = false) + public function slice(int $offset, ?int $length = null, bool $preserveKeys = false) { return static::create( \array_slice( @@ -6719,7 +6719,7 @@ static function ($value) use ($sorter) { * @phpstan-return static * @psalm-mutation-free */ - public function splice(int $offset, int $length = null, $replacement = []): self + public function splice(int $offset, ?int $length = null, $replacement = []): self { $tmpArray = $this->toArray(); @@ -6967,7 +6967,7 @@ public function toJson(int $options = 0, int $depth = 512): string * * @phpstan-return static> */ - public function toPermutation(array $items = null, array $helper = []): self + public function toPermutation(?array $items = null, array $helper = []): self { // init $return = []; diff --git a/src/ArrayyRewindableExtendedGenerator.php b/src/ArrayyRewindableExtendedGenerator.php index 2268144..ea75a65 100644 --- a/src/ArrayyRewindableExtendedGenerator.php +++ b/src/ArrayyRewindableExtendedGenerator.php @@ -15,7 +15,7 @@ class ArrayyRewindableExtendedGenerator extends ArrayyRewindableGenerator { public function __construct( callable $generatorConstructionFunction, - callable $onRewind = null, + ?callable $onRewind = null, string $class = '' ) { parent::__construct( diff --git a/src/ArrayyRewindableGenerator.php b/src/ArrayyRewindableGenerator.php index 8bb582e..cdaadb7 100644 --- a/src/ArrayyRewindableGenerator.php +++ b/src/ArrayyRewindableGenerator.php @@ -49,7 +49,7 @@ class ArrayyRewindableGenerator extends \ArrayIterator */ public function __construct( callable $generatorConstructionFunction, - callable $onRewind = null, + ?callable $onRewind = null, string $class = '' ) { $this->class = $class; diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php index 5867299..8998d0b 100644 --- a/src/Collection/Collection.php +++ b/src/Collection/Collection.php @@ -102,9 +102,9 @@ class Collection extends AbstractCollection */ public function __construct( $data = [], - string $iteratorClass = null, - bool $checkPropertiesInConstructor = null, - TypeInterface $type = null + ?string $iteratorClass = null, + ?bool $checkPropertiesInConstructor = null, + ?TypeInterface $type = null ) { // fallback if ($iteratorClass === null) { diff --git a/src/Collection/CollectionInterface.php b/src/Collection/CollectionInterface.php index c33db5f..8a1ea34 100644 --- a/src/Collection/CollectionInterface.php +++ b/src/Collection/CollectionInterface.php @@ -496,7 +496,7 @@ public function set($key, $value); * * @phpstan-return CollectionInterface */ - public function slice(int $offset, int $length = null, bool $preserveKeys = false); + public function slice(int $offset, ?int $length = null, bool $preserveKeys = false); /** * Gets a native PHP array representation of the collection. diff --git a/src/StaticArrayy.php b/src/StaticArrayy.php index c7b2859..baf1300 100644 --- a/src/StaticArrayy.php +++ b/src/StaticArrayy.php @@ -75,7 +75,7 @@ public static function __callStatic(string $name, $arguments) * @psalm-suppress InvalidReturnStatement - why? * @psalm-suppress InvalidReturnType - why? */ - public static function range(int $base, int $stop = null, int $step = 1): Arrayy + public static function range(int $base, ?int $stop = null, int $step = 1): Arrayy { if ($stop !== null) { $start = $base; diff --git a/src/Type/InstanceCollection.php b/src/Type/InstanceCollection.php index 8bbe984..4655fe4 100644 --- a/src/Type/InstanceCollection.php +++ b/src/Type/InstanceCollection.php @@ -26,8 +26,8 @@ final class InstanceCollection extends Collection implements TypeInterface */ public function __construct( array $data = [], - string $iteratorClass = null, - bool $checkPropertiesInConstructor = null, + ?string $iteratorClass = null, + ?bool $checkPropertiesInConstructor = null, $className = null ) { // fallback diff --git a/src/Type/InstancesCollection.php b/src/Type/InstancesCollection.php index d8ca3bf..11dcb43 100644 --- a/src/Type/InstancesCollection.php +++ b/src/Type/InstancesCollection.php @@ -26,9 +26,9 @@ final class InstancesCollection extends Collection implements TypeInterface */ public function __construct( array $data = [], - string $iteratorClass = null, - bool $checkPropertiesInConstructor = null, - array $classNames = null + ?string $iteratorClass = null, + ?bool $checkPropertiesInConstructor = null, + ?array $classNames = null ) { // fallback if ($iteratorClass === null) {