Refactor phpstan errors.

This commit is contained in:
James Cole
2023-10-29 17:41:14 +01:00
parent 5e32878d01
commit 12675dd950
60 changed files with 297 additions and 386 deletions

View File

@@ -24,46 +24,36 @@ declare(strict_types=1);
namespace FireflyIII\Rules;
use Illuminate\Contracts\Validation\Rule;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
/**
* Class IsBoolean
*/
class IsBoolean implements Rule
class IsBoolean implements ValidationRule
{
/**
* Get the validation error message.
*
* @return string
*/
public function message(): string
{
return (string)trans('validation.boolean');
}
/**
* Determine if the validation rule passes.
* @param string $attribute
* @param mixed $value
* @param Closure $fail
*
* @param string $attribute
* @param mixed $value
*
* @return bool
* @return void
*/
public function passes($attribute, $value): bool
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (is_bool($value)) {
return true;
return;
}
if (is_int($value) && 0 === $value) {
return true;
if (0 === $value) {
return;
}
if (is_int($value) && 1 === $value) {
return true;
if (1 === $value) {
return;
}
if (is_string($value) && in_array($value, ['0', '1', 'true', 'false', 'on', 'off', 'yes', 'no', 'y', 'n'], true)) {
return true;
if (in_array($value, ['0', '1', 'true', 'false', 'on', 'off', 'yes', 'no', 'y', 'n'], true)) {
return;
}
return false;
$fail('validation.boolean')->translate();
}
}