Skip to content

Commit

Permalink
None should return never not null (#42)
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
  • Loading branch information
ghostwriter committed Jul 5, 2023
2 parents 4c72580 + 461fae3 commit e3b4db3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ interface SomeInterface extends OptionInterface
/**
* @immutable
*
* @template TNone of null
* @template TNone of never
*
* @extends OptionInterface<TNone>
*/
Expand Down
9 changes: 3 additions & 6 deletions src/AbstractOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@
use Generator;
use Ghostwriter\Option\Exception\NullPointerException;
use Ghostwriter\Option\Exception\OptionException;
use Ghostwriter\Option\Tests\Unit\NoneTest;
use Ghostwriter\Option\Tests\Unit\OptionTest;
use Ghostwriter\Option\Tests\Unit\SomeTest;
use Throwable;

/**
* @template TOption
*
* @implements OptionInterface<TOption>
*
* @see OptionTest
* @see SomeTest
* @see NoneTest
* @see \Ghostwriter\Option\Tests\Unit\OptionTest
* @see \Ghostwriter\Option\Tests\Unit\SomeTest
* @see \Ghostwriter\Option\Tests\Unit\NoneTest
*/
abstract class AbstractOption implements OptionInterface
{
Expand Down
11 changes: 6 additions & 5 deletions src/None.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

namespace Ghostwriter\Option;

use Ghostwriter\Option\Tests\Unit\NoneTest;

/**
* @template TNone of null
* @template TNone of never
*
* @extends AbstractOption<TNone>
*
* @implements NoneInterface<TNone>
*
* @see NoneTest
* @see \Ghostwriter\Option\Tests\Unit\NoneTest
*/
final class None extends AbstractOption implements NoneInterface
{
Expand All @@ -22,6 +20,9 @@ final class None extends AbstractOption implements NoneInterface
/** @return self<TNone> */
public static function create(): self
{
return self::$none ??= new self(null);
/** @var TNone $none */
$none = null;

return self::$none ??= new self($none);
}
}
2 changes: 1 addition & 1 deletion src/NoneInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @immutable
*
* @template TNone of null
* @template TNone of never
*
* @extends OptionInterface<TNone>
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Ghostwriter\Option;

/** @see OptionTest */
/**
* @see \Ghostwriter\Option\Tests\Unit\OptionTest
*/
final class Option
{
/**
Expand Down
3 changes: 1 addition & 2 deletions src/Some.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Ghostwriter\Option;

use Ghostwriter\Option\Exception\NullPointerException;
use Ghostwriter\Option\Tests\Unit\SomeTest;

/**
* @template TSome
Expand All @@ -14,7 +13,7 @@
*
* @implements SomeInterface<TSome>
*
* @see SomeTest
* @see \Ghostwriter\Option\Tests\Unit\SomeTest
*/
final class Some extends AbstractOption implements SomeInterface
{
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/NoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
final class NoneTest extends TestCase
{
/**
* @return Generator<array-key, array{0:class-string,1:mixed}>
* @template TNone of null
*
* @return Generator<array-key, array{0:class-string<NoneInterface>,1:None|TNone}>
*/
public static function ofDataProvider(): Generator
{
Expand Down

0 comments on commit e3b4db3

Please sign in to comment.