Skip to content

Commit

Permalink
Remove internal Choice class
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Dec 17, 2024
1 parent 01b74e8 commit a6ec7bf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 60 deletions.
4 changes: 2 additions & 2 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
'path' => __DIR__ . '/src/Nexus/Collection/Collection.php',
];
$ignoreErrors[] = [
'message' => '#^Method Nexus\\\\Option\\\\Choice\\:\\:from\\(\\) never returns Nexus\\\\Option\\\\Some\\<T of mixed\\> so it can be removed from the return type\\.$#',
'message' => '#^Function Nexus\\\\Option\\\\option\\(\\) never returns Nexus\\\\Option\\\\Some\\<T of mixed\\> so it can be removed from the return type\\.$#',
'identifier' => 'return.unusedType',
'count' => 1,
'path' => __DIR__ . '/src/Nexus/Option/Choice.php',
'path' => __DIR__ . '/src/Nexus/Option/functions.php',
];
$ignoreErrors[] = [
'message' => '#^Method Nexus\\\\Tests\\\\AutoReview\\\\ComposerJsonTest\\:\\:getComposer\\(\\) should return array\\<string, mixed\\> but returns mixed\\.$#',
Expand Down
43 changes: 0 additions & 43 deletions src/Nexus/Option/Choice.php

This file was deleted.

6 changes: 5 additions & 1 deletion src/Nexus/Option/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@
*/
function option(mixed $value, mixed $none = null): Option
{
return Choice::from($value, $none);
if ($value === $none) {
return new None();
}

return new Some($value);
}
12 changes: 1 addition & 11 deletions tests/Option/ChoiceTest.php → tests/Option/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@

namespace Nexus\Tests\Option;

use Nexus\Option\Choice;
use Nexus\Option\None;
use Nexus\Option\Some;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\CoversFunction;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
Expand All @@ -26,18 +24,10 @@
/**
* @internal
*/
#[CoversClass(Choice::class)]
#[CoversFunction('Nexus\Option\option')]
#[Group('unit-test')]
final class ChoiceTest extends TestCase
final class FunctionsTest extends TestCase
{
public function testChoiceFrom(): void
{
self::assertInstanceOf(Some::class, Choice::from(2));
self::assertInstanceOf(None::class, Choice::from(null));
self::assertInstanceOf(Some::class, Choice::from(null, false));
}

public function testOptionFunction(): void
{
self::assertInstanceOf(Some::class, option(2));
Expand Down
6 changes: 3 additions & 3 deletions tests/Option/data/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

namespace Nexus\Tests\Option;

use Nexus\Option\Choice;
use Nexus\Option\None;
use Nexus\Option\Option;
use Nexus\Option\Some;

use function Nexus\Option\option;
use function PHPStan\Testing\assertType;

assertType(None::class, Choice::from(null));
assertType(None::class, option(null));
assertType(None::class, new None());
assertType('Nexus\Option\Some<null>', Choice::from(null, false));
assertType('Nexus\Option\Some<null>', option(null, false));
assertType('Nexus\Option\Some<int>', new Some(2));

function testOption(Option $option): void
Expand Down

0 comments on commit a6ec7bf

Please sign in to comment.