diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a30b839..9e72aa19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased] + +### Fixed + +- Support for PHP `8.4` + ## 5.11.0 - 2024-12-01 ### Added diff --git a/composer.json b/composer.json index 90bc86c4..f1c118b8 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ } }, "require-dev": { - "vimeo/psalm": "~5.6", + "vimeo/psalm": "~5.6|dev-master", "innmind/black-box": "^5.5.1", "innmind/coding-standard": "~2.0" }, diff --git a/fixtures/Sequence.php b/fixtures/Sequence.php index 849fc905..d957d00d 100644 --- a/fixtures/Sequence.php +++ b/fixtures/Sequence.php @@ -18,7 +18,7 @@ final class Sequence * * @return Set> */ - public static function of(Set $set, Set\Integers $sizes = null): Set + public static function of(Set $set, ?Set\Integers $sizes = null): Set { // this is not optimal but it allows to avoid a BC break $sizes ??= Set\Integers::between(0, 100); diff --git a/fixtures/Set.php b/fixtures/Set.php index b367bb76..b96f8437 100644 --- a/fixtures/Set.php +++ b/fixtures/Set.php @@ -21,7 +21,7 @@ final class Set * * @return Set> */ - public static function of(DataSet $set, DataSet\Integers $sizes = null): DataSet + public static function of(DataSet $set, ?DataSet\Integers $sizes = null): DataSet { // this is not optimal but it allows to avoid a BC break $sizes ??= DataSet\Integers::between(0, 100); diff --git a/src/Accumulate.php b/src/Accumulate.php index 89a650f3..7e0c842b 100644 --- a/src/Accumulate.php +++ b/src/Accumulate.php @@ -38,6 +38,7 @@ public function current(): mixed /** @psalm-suppress UnusedMethodCall */ $this->pop(); + /** @var S */ return \current($this->values); } diff --git a/src/Map/DoubleIndex.php b/src/Map/DoubleIndex.php index 52e9516e..41ae1031 100644 --- a/src/Map/DoubleIndex.php +++ b/src/Map/DoubleIndex.php @@ -26,7 +26,7 @@ final class DoubleIndex implements Implementation /** * @param Sequence\Implementation> $pairs */ - public function __construct(Sequence\Implementation $pairs = null) + public function __construct(?Sequence\Implementation $pairs = null) { /** @var Sequence\Implementation> */ $this->pairs = $pairs ?? new Sequence\Primitive; diff --git a/src/Map/ObjectKeys.php b/src/Map/ObjectKeys.php index 78749e15..98bd403a 100644 --- a/src/Map/ObjectKeys.php +++ b/src/Map/ObjectKeys.php @@ -22,7 +22,7 @@ final class ObjectKeys implements Implementation { private \SplObjectStorage $values; - public function __construct(\SplObjectStorage $values = null) + public function __construct(?\SplObjectStorage $values = null) { $this->values = $values ?? new \SplObjectStorage; } diff --git a/src/Monoid/Append.php b/src/Monoid/Append.php index ed87dc00..2bc2ea3b 100644 --- a/src/Monoid/Append.php +++ b/src/Monoid/Append.php @@ -22,7 +22,7 @@ final class Append implements Monoid * * @return self */ - public static function of(string $class = null): self + public static function of(?string $class = null): self { /** @var self */ return new self; diff --git a/src/Monoid/MergeMap.php b/src/Monoid/MergeMap.php index 8a7db5c0..1fca56ad 100644 --- a/src/Monoid/MergeMap.php +++ b/src/Monoid/MergeMap.php @@ -25,7 +25,7 @@ final class MergeMap implements Monoid * * @return self */ - public static function of(string $key = null, string $value = null): self + public static function of(?string $key = null, ?string $value = null): self { /** @var self */ return new self; diff --git a/src/Monoid/MergeSet.php b/src/Monoid/MergeSet.php index 25cc16a3..a5e2f53f 100644 --- a/src/Monoid/MergeSet.php +++ b/src/Monoid/MergeSet.php @@ -22,7 +22,7 @@ final class MergeSet implements Monoid * * @return self */ - public static function of(string $class = null): self + public static function of(?string $class = null): self { /** @var self */ return new self; diff --git a/src/Sequence/Aggregate.php b/src/Sequence/Aggregate.php index 1e378ca9..e0198899 100644 --- a/src/Sequence/Aggregate.php +++ b/src/Sequence/Aggregate.php @@ -58,7 +58,10 @@ public function __invoke(callable $map): \Generator /** @psalm-suppress ImpureMethodCall */ while ($this->values->valid()) { - /** @psalm-suppress ImpureFunctionCall */ + /** + * @psalm-suppress PossiblyNullArgument + * @psalm-suppress ImpureFunctionCall + */ $aggregate = $this->walk($map($n2, $n1), $void); foreach ($aggregate as $element) { diff --git a/src/Sequence/Lazy.php b/src/Sequence/Lazy.php index fcf8ac38..5f8731a8 100644 --- a/src/Sequence/Lazy.php +++ b/src/Sequence/Lazy.php @@ -860,6 +860,7 @@ public function dropWhile(callable $condition): self /** * @psalm-suppress ImpureMethodCall * @psalm-suppress ImpureFunctionCall + * @psalm-suppress PossiblyNullArgument */ if (!$condition($generator->current())) { /** @psalm-suppress ImpureMethodCall */ diff --git a/src/Sequence/Primitive.php b/src/Sequence/Primitive.php index 644fa5e1..6e5e1734 100644 --- a/src/Sequence/Primitive.php +++ b/src/Sequence/Primitive.php @@ -609,6 +609,7 @@ public function dropWhile(callable $condition): self /** * @psalm-suppress ImpureMethodCall * @psalm-suppress ImpureFunctionCall + * @psalm-suppress PossiblyNullArgument */ if (!$condition($iterator->current())) { /** @psalm-suppress ImpureMethodCall */ diff --git a/src/Str.php b/src/Str.php index 3a169f1d..c861fb6e 100644 --- a/src/Str.php +++ b/src/Str.php @@ -13,7 +13,7 @@ final class Str implements \Stringable private string $value; private Str\Encoding $encoding; - private function __construct(string $value, Str\Encoding $encoding = null) + private function __construct(string $value, ?Str\Encoding $encoding = null) { $this->value = $value; $this->encoding = $encoding ?? Str\Encoding::utf8; @@ -27,7 +27,7 @@ public function __toString(): string /** * @psalm-pure */ - public static function of(string $value, Str\Encoding $encoding = null): self + public static function of(string $value, ?Str\Encoding $encoding = null): self { return new self($value, $encoding); } @@ -75,7 +75,7 @@ public function maybe(callable $filter): Maybe * * @return Sequence */ - public function split(string $delimiter = null): Sequence + public function split(?string $delimiter = null): Sequence { if (\is_null($delimiter) || $delimiter === '') { return $this->chunk(); @@ -279,12 +279,20 @@ public function words(string|\Stringable $charlist = ''): Map /** * Split the string using a regular expression * + * @throws InvalidRegex If the split didn't work + * * @return Sequence */ public function pregSplit(string|\Stringable $regex, int $limit = -1): Sequence { /** @psalm-suppress ArgumentTypeCoercion */ $strings = \preg_split((string) $regex, $this->value, $limit); + + if ($strings === false) { + /** @psalm-suppress ImpureFunctionCall */ + throw new InvalidRegex('', \preg_last_error()); + } + /** @var Sequence */ $sequence = Sequence::of(); @@ -348,7 +356,7 @@ public function pregReplace( * * @param 0|positive-int $length */ - public function substring(int $start, int $length = null): self + public function substring(int $start, ?int $length = null): self { if ($this->empty()) { return $this; @@ -462,7 +470,7 @@ public function equals(self $string): bool /** * Trim the string */ - public function trim(string $mask = null): self + public function trim(?string $mask = null): self { return new self( $mask === null ? \trim($this->value) : \trim($this->value, $mask), @@ -473,7 +481,7 @@ public function trim(string $mask = null): self /** * Trim the right side of the string */ - public function rightTrim(string $mask = null): self + public function rightTrim(?string $mask = null): self { return new self( $mask === null ? \rtrim($this->value) : \rtrim($this->value, $mask), @@ -484,7 +492,7 @@ public function rightTrim(string $mask = null): self /** * Trim the left side of the string */ - public function leftTrim(string $mask = null): self + public function leftTrim(?string $mask = null): self { return new self( $mask === null ? \ltrim($this->value) : \ltrim($this->value, $mask),