-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
maximtrunnikov
committed
Feb 21, 2022
1 parent
1c16942
commit 3441d3b
Showing
15 changed files
with
413 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Maxonfjvipon\Elegant_Elephant\Logical; | ||
|
||
use Maxonfjvipon\Elegant_Elephant\Arrayable; | ||
use Maxonfjvipon\Elegant_Elephant\Logical; | ||
use Maxonfjvipon\Elegant_Elephant\Numerable\LengthOf; | ||
use Maxonfjvipon\Elegant_Elephant\Text; | ||
use Maxonfjvipon\OverloadedElephant\Overloadable; | ||
|
||
/** | ||
* Is empty. | ||
*/ | ||
final class IsEmpty implements Logical | ||
{ | ||
use Overloadable; | ||
|
||
/** | ||
* @var array|Arrayable|Text|string $value | ||
*/ | ||
private Text|string|array|Arrayable $value; | ||
|
||
/** | ||
* @param string|array|Arrayable|Text $value | ||
* @return IsEmpty | ||
*/ | ||
public static function new(string|array|Arrayable|Text $value) | ||
{ | ||
return new self($value); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param string|array|Arrayable|Text $value | ||
*/ | ||
public function __construct(string|array|Arrayable|Text $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function asBool(): bool | ||
{ | ||
return $this->overload([$this->value], [[ | ||
'string' => fn(string $str) => $str === "", | ||
'array' => fn(array $arr) => (new EqualityOf(new LengthOf($arr), 0))->asBool(), | ||
Text::class => fn(Text $txt) => (new EqualityOf($txt, ""))->asBool(), | ||
Arrayable::class => fn(Arrayable $arr) => (new EqualityOf(new LengthOf($arr), 0))->asBool() | ||
]])[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Maxonfjvipon\Elegant_Elephant\Logical; | ||
|
||
use Maxonfjvipon\Elegant_Elephant\Arrayable; | ||
use Maxonfjvipon\Elegant_Elephant\Logical; | ||
use Maxonfjvipon\Elegant_Elephant\Text; | ||
use Maxonfjvipon\OverloadedElephant\Overloadable; | ||
|
||
/** | ||
* Is not empty. | ||
*/ | ||
final class IsNotEmpty implements Logical | ||
{ | ||
use Overloadable; | ||
|
||
/** | ||
* @var array|Arrayable|Text|string $value | ||
*/ | ||
private Text|string|array|Arrayable $value; | ||
|
||
/** | ||
* @param string|array|Arrayable|Text $value | ||
* @return IsNotEmpty | ||
*/ | ||
public static function new(string|array|Arrayable|Text $value) | ||
{ | ||
return new self($value); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param string|array|Arrayable|Text $value | ||
*/ | ||
public function __construct(string|array|Arrayable|Text $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function asBool(): bool | ||
{ | ||
return (new Negation( | ||
new IsEmpty($this->value) | ||
))->asBool(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Maxonfjvipon\Elegant_Elephant\Numerable; | ||
|
||
use Maxonfjvipon\Elegant_Elephant\Numerable; | ||
|
||
/** | ||
* Max of | ||
*/ | ||
final class MaxOf implements Numerable | ||
{ | ||
use NumerableOverloaded; | ||
|
||
/** | ||
* @var float[]|int[]|Numerable[] $items | ||
*/ | ||
private array $items; | ||
|
||
/** | ||
* Ctor wrap. | ||
* @param float|int|Numerable ...$items | ||
* @return MaxOf | ||
*/ | ||
public static function new(float|int|Numerable ...$items) | ||
{ | ||
return new self(...$items); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param float|int|Numerable ...$items | ||
*/ | ||
public function __construct(float|int|Numerable ...$items) | ||
{ | ||
$this->items = $items; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function asNumber(): float|int | ||
{ | ||
return max(...$this->numerableOverloaded(...$this->items)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.