1
0
Fork 0
mirror of https://github.com/archtechx/enums.git synced 2025-12-12 11:14:05 +00:00

feat: comparable enum

This commit is contained in:
Thai Nguyen Hung 2023-06-08 09:30:31 +07:00
parent 922b6abdc1
commit b9f33f36a3

28
src/Comparable.php Normal file
View 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);
}
}