Skip to content

Commit

Permalink
refactor: refactored abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
petrknap committed May 19, 2024
1 parent 01aaae6 commit 99a846d
Show file tree
Hide file tree
Showing 14 changed files with 280 additions and 324 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ It is an easy way to make sure that everyone has to check if they have (not) rec
```php
namespace PetrKnap\Optional;

$optionalString = OptionalString::of('value');
$optionalString = Optional::of('value');

echo $optionalString->isPresent() ? $optionalString->get() : 'empty';
echo $optionalString->orElse('empty');
Expand All @@ -30,7 +30,7 @@ if ($optionalString->equals('value')) {
}

echo $optionalString->map(fn ($s) => "`{$s}`")->orElse('empty');
echo $optionalString->flatMap(fn ($s) => OptionalString::of("`{$s}`"))->orElse('empty');
echo $optionalString->flatMap(fn ($s) => Optional::of("`{$s}`"))->orElse('empty');
```

### Create and use your own typed optional
Expand Down
205 changes: 0 additions & 205 deletions src/AbstractOptional.php

This file was deleted.

29 changes: 0 additions & 29 deletions src/AbstractOptionalObject.php

This file was deleted.

29 changes: 0 additions & 29 deletions src/AbstractOptionalResource.php

This file was deleted.

22 changes: 22 additions & 0 deletions src/AnOptional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace PetrKnap\Optional;

/**
* @internal use {@see Optional}
*
* @template-extends Optional<mixed>
*/
final class AnOptional extends Optional
{
protected static function isSupported(mixed $value): bool
{
trigger_error(
self::class . ' does not check the type of value.',
error_level: E_USER_NOTICE,
);
return true;
}
}
11 changes: 11 additions & 0 deletions src/Exception/CouldNotGetValueOfEmptyOptional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace PetrKnap\Optional\Exception;

use PetrKnap\Optional\NoSuchElementException;

final class CouldNotGetValueOfEmptyOptional extends NoSuchElementException implements OptionalException
{
}
11 changes: 0 additions & 11 deletions src/Exception/NoSuchElement.php

This file was deleted.

14 changes: 14 additions & 0 deletions src/NoSuchElementException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace PetrKnap\Optional;

use RuntimeException;

/**
* @see https://docs.oracle.com/javase/8/docs/api/java/util/NoSuchElementException.html
*/
abstract class NoSuchElementException extends RuntimeException
{
}
Loading

0 comments on commit 99a846d

Please sign in to comment.