enumClass = $enumClass; } /** * Determine if the validation rule passes. * * @param string $attribute * @param mixed $value * @return boolean * @phpcs:disable Squiz.Commenting.FunctionComment.ScalarTypeHintMissing * @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing * @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed */ public function passes($attribute, $value): bool { // phpcs:enable try { return $this->enumClass::tryFrom(\strval($value)) !== false; } catch (\TypeError) { return $this->enumClass::tryFrom(\intval($value)) !== false; } } /** * Get the validation error message. * * @return string */ public function message(): string { return trans('Le champ :attribute doit ĂȘtre une des valeurs suivantes: :values', [ 'values' => collect($this->enumClass::cases())->implode(', ') ]); } }