Fix some PHPStan issues

Unfortunately, we can't automatically run PHPStan in the PHPT files
because it will complain about the "strict_types" not being declared as
the first part of the file. I did some workaround that and fixed some
issues.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2024-03-07 01:43:44 +01:00
parent fdd8c5a978
commit 235805a654
No known key found for this signature in database
GPG key ID: 221E9281655813A6
5 changed files with 10 additions and 13 deletions

View file

@ -254,7 +254,7 @@ interface ChainedValidator extends Validatable
public function pesel(): ChainedValidator;
public function phone(): ChainedValidator;
public function phone(?string $countryCode = null): ChainedValidator;
public function phpLabel(): ChainedValidator;

View file

@ -256,7 +256,7 @@ interface StaticValidator
public static function pesel(): ChainedValidator;
public static function phone(): ChainedValidator;
public static function phone(?string $countryCode = null): ChainedValidator;
public static function phpLabel(): ChainedValidator;

View file

@ -6,7 +6,7 @@ declare(strict_types=1);
use Respect\Validation\Rules\ArrayType;
use Respect\Validation\Rules\BoolType;
use Respect\Validation\Rules\Each;
use Respect\Validation\Rules\Key;
use Respect\Validation\Rules\KeyOptional;
use Respect\Validation\Rules\OneOf;
use Respect\Validation\Rules\StringType;
use Respect\Validation\Rules\StringVal;
@ -17,23 +17,20 @@ require 'vendor/autoload.php';
$validator = Validator::create(
new Each(
Validator::create(
new Key(
new KeyOptional(
'default',
new OneOf(
new StringType(),
new BoolType()
),
false
)
),
new Key(
new KeyOptional(
'description',
new StringVal(),
false
),
new Key(
new KeyOptional(
'children',
new ArrayType(),
false
)
)
)

View file

@ -8,7 +8,7 @@
declare(strict_types=1);
use Respect\Validation\Exceptions\ValidatorException;
use Respect\Validation\Validator;
use Respect\Validation\Validatable;
use Symfony\Component\VarExporter\VarExporter;
use function Respect\Stringifier\stringify;
@ -43,7 +43,7 @@ function exceptionFullMessage(callable $callable, string $fallbackMessage = 'No
}
}
/** @param array<string, array{Validator, mixed, null|string|array<string, mixed>}> $scenarios */
/** @param array<string, array{0: Validatable, 1: mixed, 2?:string|array<string, mixed>}> $scenarios */
function run(array $scenarios): void
{
foreach ($scenarios as $description => $data) {

View file

@ -10,7 +10,7 @@ use Respect\Validation\Validator as v;
run([
'Two rules' => [v::allOf(v::intType(), v::negative()), '2'],
'Wrapped by "not"' => [v::not(v::allOf(v::intType(), v::positive())), 3],
'Wrapping "not"' => [v::allOf(v::not(v::intType(), v::positive()), v::greaterThan(2)), 4],
'Wrapping "not"' => [v::allOf(v::not(v::intType()), v::greaterThan(2)), 4],
'With a single template' => [v::allOf(v::stringType(), v::arrayType()), 5, 'This is a single template'],
'With multiple templates' => [
v::allOf(v::stringType(), v::uppercase()),