You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
615 B
23 lines
615 B
<?php
|
|
|
|
namespace App\Domains\System\Traits\Enum;
|
|
|
|
trait HasPredicateMethod
|
|
{
|
|
public function __call(string $method, array $arguments): bool
|
|
{
|
|
if (str_starts_with($method, 'is')) {
|
|
$expectedCase = substr($method, 2);
|
|
$expectedCase = strtoupper($expectedCase);
|
|
foreach ($this::cases() as $case) {
|
|
if ($case->name === $expectedCase) {
|
|
return $this === $case;
|
|
}
|
|
}
|
|
|
|
throw new \BadMethodCallException("Method {$method} does not exist on ".self::class);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|