From c049210aeed7347058d586853b6373e00ac73650 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 2 Jun 2024 09:59:29 +0200 Subject: [PATCH 1/7] test against php 8.4 --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e077eff..91a19ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest] - php-version: ['8.2', '8.3'] + php-version: ['8.2', '8.3', '8.4'] dependency-versions: ['lowest', 'highest'] name: 'BlackBox' steps: @@ -33,7 +33,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest] - php-version: ['8.2', '8.3'] + php-version: ['8.2', '8.3', '8.4'] dependency-versions: ['lowest', 'highest'] name: 'Coverage' steps: @@ -61,7 +61,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['8.2', '8.3'] + php-version: ['8.2', '8.3', '8.4'] name: 'Psalm' steps: - name: Checkout From dbf8df055757bd33845ed65eb69c7d3b6769246b Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 16 Jan 2025 16:02:05 +0100 Subject: [PATCH 2/7] run psalm against php 8.4 --- .github/workflows/ci.yml | 10 +++++++++- composer.json | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c48d37..ec19358 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,15 @@ jobs: uses: innmind/github-workflows/.github/workflows/coverage-matrix.yml@main secrets: inherit psalm: - uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main + uses: innmind/github-workflows/.github/workflows/psalm.yml@main + strategy: + matrix: + php-version: ['8.2', '8.3', '8.4'] + dependency-versions: ['lowest', 'highest'] + name: 'Psalm' + with: + php-version: ${{ matrix.php-version }} + dependency-versions: ${{ matrix.dependency-versions }} cs: uses: innmind/github-workflows/.github/workflows/cs.yml@main with: diff --git a/composer.json b/composer.json index 90bc86c..f1c118b 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" }, From a94f4fbeb15b89853a87a2605a359c2e3376ca9f Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 16 Jan 2025 16:09:31 +0100 Subject: [PATCH 3/7] fix psalm errors --- src/Accumulate.php | 1 + src/Sequence/Aggregate.php | 5 ++++- src/Sequence/Lazy.php | 1 + src/Sequence/Primitive.php | 1 + src/Str.php | 6 ++++++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Accumulate.php b/src/Accumulate.php index 89a650f..7e0c842 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/Sequence/Aggregate.php b/src/Sequence/Aggregate.php index 1e378ca..e019889 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 fcf8ac3..5f8731a 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 644fa5e..6e5e173 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 3a169f1..f485bca 100644 --- a/src/Str.php +++ b/src/Str.php @@ -285,6 +285,12 @@ 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(); From 5d68c8a97f49e91d4157e1c026703d083084cdd1 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 16 Jan 2025 16:29:09 +0100 Subject: [PATCH 4/7] fix php 8.4 null deprecations --- fixtures/Sequence.php | 2 +- fixtures/Set.php | 2 +- src/Map/DoubleIndex.php | 2 +- src/Map/ObjectKeys.php | 2 +- src/Monoid/Append.php | 2 +- src/Monoid/MergeMap.php | 2 +- src/Monoid/MergeSet.php | 2 +- src/Str.php | 14 +++++++------- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/fixtures/Sequence.php b/fixtures/Sequence.php index 849fc90..d957d00 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 b367bb7..b96f843 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/Map/DoubleIndex.php b/src/Map/DoubleIndex.php index 52e9516..41ae103 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 78749e1..98bd403 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 ed87dc0..2bc2ea3 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 8a7db5c..1fca56a 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 25cc16a..a5e2f53 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/Str.php b/src/Str.php index f485bca..29cbf91 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(); @@ -354,7 +354,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; @@ -468,7 +468,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), @@ -479,7 +479,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), @@ -490,7 +490,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), From 2a5012f2e625f96484442be0fab96aa53b55170d Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 16 Jan 2025 16:30:43 +0100 Subject: [PATCH 5/7] use the default psalm matrix --- .github/workflows/ci.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec19358..0c48d37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,15 +11,7 @@ jobs: uses: innmind/github-workflows/.github/workflows/coverage-matrix.yml@main secrets: inherit psalm: - uses: innmind/github-workflows/.github/workflows/psalm.yml@main - strategy: - matrix: - php-version: ['8.2', '8.3', '8.4'] - dependency-versions: ['lowest', 'highest'] - name: 'Psalm' - with: - php-version: ${{ matrix.php-version }} - dependency-versions: ${{ matrix.dependency-versions }} + uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main cs: uses: innmind/github-workflows/.github/workflows/cs.yml@main with: From 0e03a3a56f195ae1ddda3209eaaa516bc0fc5ba4 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 16 Jan 2025 16:43:02 +0100 Subject: [PATCH 6/7] add missing annotation --- src/Str.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Str.php b/src/Str.php index 29cbf91..c861fb6 100644 --- a/src/Str.php +++ b/src/Str.php @@ -279,6 +279,8 @@ 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 From 233c026aeb81c1caeb35b616b8f34a269b435b5d Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Thu, 16 Jan 2025 16:44:12 +0100 Subject: [PATCH 7/7] mention php 8.4 support in the changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a30b83..9e72aa1 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