Skip to content

Commit

Permalink
feat: replace phpoption/phpoption with azjezz/psl (#46)
Browse files Browse the repository at this point in the history
azjezz/psl is more adopted within our code bases
  • Loading branch information
simPod authored Apr 18, 2024
1 parent f83ca40 commit 00aa917
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use function Cdn77\Functions\Iterable\find;
$iterable = [0, 1, 2, 3];
$option = find($iterable, static fn (mixed $_, int $value) => $value < 2);

assert($option->get() === 0);
assert($option->unwrap() === 0);
```

[GA Image]: https://github.com/cdn77/PhpFunctions/workflows/CI/badge.svg
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"require": {
"php": "^8.2",
"ext-ds": "*",
"phpoption/phpoption": "^1.9"
"azjezz/psl": "^2.9"
},
"require-dev": {
"cdn77/coding-standard": "^7.0",
Expand Down
8 changes: 3 additions & 5 deletions src/iterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace Cdn77\Functions\Iterable;

use PhpOption\None;
use PhpOption\Option;
use PhpOption\Some;
use Psl\Option\Option;

/**
* @param iterable<K, T> $iterable
Expand All @@ -21,9 +19,9 @@ function find(iterable $iterable, callable $filterFn): Option
{
foreach ($iterable as $k => $v) {
if ($filterFn($k, $v)) {
return new Some($v);
return Option::some($v);
}
}

return None::create();
return Option::none();
}
5 changes: 2 additions & 3 deletions tests/IterableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Cdn77\Functions\Tests;

use PhpOption\None;
use PHPUnit\Framework\Attributes\CoversFunction;
use PHPUnit\Framework\TestCase;

Expand All @@ -18,14 +17,14 @@ public function testFindFirst(): void
$iterable = [0, 1, 2, 3];
$option = find($iterable, static fn (mixed $_, int $value) => $value < 2);

self::assertSame(0, $option->getOrElse(null));
self::assertSame(0, $option->unwrapOr(null));
}

public function testDontFind(): void
{
$iterable = [0, 1, 2, 3];
$option = find($iterable, static fn (mixed $_, int $value) => $value > 3);

self::assertSame(None::create(), $option);
self::assertTrue($option->isNone());
}
}

0 comments on commit 00aa917

Please sign in to comment.