mirror of
https://github.com/archtechx/enums.git
synced 2025-12-12 13:54:04 +00:00
feat: comparable enum
This commit is contained in:
parent
922b6abdc1
commit
b9f33f36a3
1 changed files with 28 additions and 0 deletions
28
src/Comparable.php
Normal file
28
src/Comparable.php
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace ArchTech\Enums;
|
||||||
|
|
||||||
|
trait Comparable
|
||||||
|
{
|
||||||
|
public function is(mixed $enum): bool
|
||||||
|
{
|
||||||
|
return $this === $enum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isNot(mixed $enum): bool
|
||||||
|
{
|
||||||
|
return ! $this->is($enum);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function in(array $enums): bool
|
||||||
|
{
|
||||||
|
return [] !== array_filter($enums, fn (mixed $enum) => $this->is($enum));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function notIn(array $enums): bool
|
||||||
|
{
|
||||||
|
return ! $this->in($enums);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue