Skip to content

Commit

Permalink
Fix some PHPStan issues
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
henriquemoody committed Mar 7, 2024
1 parent fdd8c5a commit 235805a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion library/Mixins/ChainedValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public function perfectSquare(): ChainedValidator;

public function pesel(): ChainedValidator;

public function phone(): ChainedValidator;
public function phone(?string $countryCode = null): ChainedValidator;

public function phpLabel(): ChainedValidator;

Expand Down
2 changes: 1 addition & 1 deletion library/Mixins/StaticValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public static function perfectSquare(): ChainedValidator;

public static function pesel(): ChainedValidator;

public static function phone(): ChainedValidator;
public static function phone(?string $countryCode = null): ChainedValidator;

public static function phpLabel(): ChainedValidator;

Expand Down
13 changes: 5 additions & 8 deletions tests/integration/issue-1289.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/lib/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/rules/allOf.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down

0 comments on commit 235805a

Please sign in to comment.