Skip to content

Commit

Permalink
refactor: Rename the Match class.
Browse files Browse the repository at this point in the history
To avoid name collision with match keyword in PHP >= 8.
The Collection API hasn't changed.
  • Loading branch information
drupol committed Dec 27, 2020
1 parent 6acbd55 commit 74d3682
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
use loophp\collection\Operation\Limit;
use loophp\collection\Operation\Lines;
use loophp\collection\Operation\Map;
use loophp\collection\Operation\Match;
use loophp\collection\Operation\MatchOne;
use loophp\collection\Operation\Merge;
use loophp\collection\Operation\Normalize;
use loophp\collection\Operation\Nth;
Expand Down Expand Up @@ -536,7 +536,11 @@ public function match(callable $callback, ?callable $matcher = null): Collection
{
$matcher = $matcher ?? static fn () => true;

return new self(Match::of()($matcher)($callback), $this->getIterator());
// @todo: Rename this in next major version.
// We cannot use Match::class because PHP 8 has
// a new "match" function and we cannot use the same name.
// @See https://github.com/loophp/collection/issues/56
return new self(MatchOne::of()($matcher)($callback), $this->getIterator());
}

public function merge(iterable ...$sources): CollectionInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Falsy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __invoke(): Closure

/** @psalm-var Closure(Iterator<TKey, T>): Generator<int, bool> $pipe */
$pipe = Pipe::of()(
Match::of()(static fn () => true)($matchCallback),
MatchOne::of()(static fn () => true)($matchCallback),
Map::of()($mapCallback),
);

Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Has.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static function (callable $callback): Closure {
static fn ($value) => $value;

/** @psalm-var Closure(Iterator<TKey, T>): Generator<int, bool> $match */
$match = Match::of()($matcher)($callback);
$match = MatchOne::of()($matcher)($callback);

// Point free style.
return $match;
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Match.php → src/Operation/MatchOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* phpcs:disable Generic.Files.LineLength.TooLong
*/
final class Match extends AbstractOperation
final class MatchOne extends AbstractOperation
{
/**
* @psalm-return Closure(callable(T, TKey, Iterator<TKey, T>): T): Closure(callable(T, TKey, Iterator<TKey, T>): T): Closure(Iterator<TKey, T>): Generator<int, bool>
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Nullsy.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __invoke(): Closure

/** @psalm-var Closure(Iterator<TKey, T>): Generator<int, bool> $pipe */
$pipe = Pipe::of()(
Match::of()(static fn () => false)($mapCallback),
MatchOne::of()(static fn () => false)($mapCallback),
Map::of()(static fn ($value) => !$value),
);

Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Truthy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __invoke(): Closure

/** @psalm-var Closure(Iterator<TKey, T>): Generator<int, bool> $pipe */
$pipe = Pipe::of()(
Match::of()(static fn () => true)($matchCallback),
MatchOne::of()(static fn () => true)($matchCallback),
Map::of()($mapCallback),
);

Expand Down

0 comments on commit 74d3682

Please sign in to comment.