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 24, 2024
1 parent aa894a1 commit 41d4a79
Show file tree
Hide file tree
Showing 24 changed files with 443 additions and 328 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ It is an easy way to make sure that everyone has to check if they have (not) rec
```php
namespace PetrKnap\Optional;

Optional::setLogger(new \Psr\Log\NullLogger());

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

echo $optionalString->isPresent() ? $optionalString->get() : 'empty';
echo $optionalString->orElse('empty');
Expand All @@ -32,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 All @@ -46,7 +44,7 @@ class YourClass {}
* @template-extends OptionalObject<YourClass>
*/
class YourOptional extends OptionalObject {
protected static function getObjectClassName(): string {
protected static function getInstanceOf(): string {
return YourClass::class;
}
}
Expand Down
204 changes: 0 additions & 204 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.

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\JavaSe8\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/JavaSe8/NoSuchElementException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace PetrKnap\Optional\JavaSe8;

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 41d4a79

Please sign in to comment.