Skip to content

Commit

Permalink
Merge pull request #17 from Innmind/php-84
Browse files Browse the repository at this point in the history
Add PHP 8.4 support
  • Loading branch information
Baptouuuu authored Jan 16, 2025
2 parents 4503a1b + 233c026 commit 8787f66
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Fixed

- Support for PHP `8.4`

## 5.11.0 - 2024-12-01

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion fixtures/Sequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class Sequence
*
* @return Set<Structure<I>>
*/
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);
Expand Down
2 changes: 1 addition & 1 deletion fixtures/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class Set
*
* @return Set<Structure<I>>
*/
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);
Expand Down
1 change: 1 addition & 0 deletions src/Accumulate.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function current(): mixed
/** @psalm-suppress UnusedMethodCall */
$this->pop();

/** @var S */
return \current($this->values);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Map/DoubleIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class DoubleIndex implements Implementation
/**
* @param Sequence\Implementation<Pair<T, S>> $pairs
*/
public function __construct(Sequence\Implementation $pairs = null)
public function __construct(?Sequence\Implementation $pairs = null)
{
/** @var Sequence\Implementation<Pair<T, S>> */
$this->pairs = $pairs ?? new Sequence\Primitive;
Expand Down
2 changes: 1 addition & 1 deletion src/Map/ObjectKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Monoid/Append.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class Append implements Monoid
*
* @return self<C>
*/
public static function of(string $class = null): self
public static function of(?string $class = null): self
{
/** @var self<C> */
return new self;
Expand Down
2 changes: 1 addition & 1 deletion src/Monoid/MergeMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class MergeMap implements Monoid
*
* @return self<A, B>
*/
public static function of(string $key = null, string $value = null): self
public static function of(?string $key = null, ?string $value = null): self
{
/** @var self<A, B> */
return new self;
Expand Down
2 changes: 1 addition & 1 deletion src/Monoid/MergeSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class MergeSet implements Monoid
*
* @return self<C>
*/
public static function of(string $class = null): self
public static function of(?string $class = null): self
{
/** @var self<C> */
return new self;
Expand Down
5 changes: 4 additions & 1 deletion src/Sequence/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/Sequence/Lazy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions src/Sequence/Primitive.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
22 changes: 15 additions & 7 deletions src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -75,7 +75,7 @@ public function maybe(callable $filter): Maybe
*
* @return Sequence<self>
*/
public function split(string $delimiter = null): Sequence
public function split(?string $delimiter = null): Sequence
{
if (\is_null($delimiter) || $delimiter === '') {
return $this->chunk();
Expand Down Expand Up @@ -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<self>
*/
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<self> */
$sequence = Sequence::of();

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down

0 comments on commit 8787f66

Please sign in to comment.