Skip to content

Commit

Permalink
phpstan errors fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Triplkrypl committed Dec 14, 2024
1 parent d041b28 commit 4d64fb8
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/Rule/General/InRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class InRule extends ReadableRule
{
/**
* @param RuleChain<Tin> $ruleChain
* @param Validated<mixed> $validated
* @param Validated<covariant mixed> $validated
* @param non-empty-string $valueName
* @param non-empty-array<Tout> $values
*/
Expand Down
3 changes: 0 additions & 3 deletions src/Rule/Numeric/Numeric.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public function maxDecimal(int $max): Max
/** @var Max<numeric-string, int> $maxRule */
$maxRule = new Max(
$this->exceptionFactory(),
/** @phpstan-ignore-next-line */
$this->ruleChain(),
$this->validated(),
$this->valueName(),
Expand Down Expand Up @@ -93,11 +92,9 @@ public function exactDigit(int $number, int $maxDecimal = 0): Max
{
$same = new Same(
$this->exceptionFactory(),
/** @phpstan-ignore-next-line */
$this->ruleChain(),
$this->validated(),
$this->valueName(),
/** @phpstan-ignore-next-line */
new DigitCount(),
$number,
'digits before decimals'
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Object/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class Property extends Rule
{
/**
* @param RuleChain<object> $ruleChain
* @param Validated<mixed> $validated
* @param Validated<covariant mixed> $validated
* @param non-empty-string $valueName
*/
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/String/CaseInsensitiveInRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class CaseInsensitiveInRule extends InRule
{
/**
* @param RuleChain<string> $ruleChain
* @param Validated<mixed> $validated
* @param Validated<covariant mixed> $validated
* @param non-empty-string $valueName
* @param non-empty-array<Tout> $values
*/
Expand Down
6 changes: 2 additions & 4 deletions src/Rule/String/InRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ public function __construct(
bool $ignoreCharacterSize
) {
if ($ignoreCharacterSize) {
/** @var non-empty-array<Tout> $values */
$values = array_map(fn (string $value): string => strtolower($value), $values);
}

/** @phpstan-ignore-next-line todo rewrite char size ignore */
/** @phpstan-ignore-next-line */
parent::__construct($exceptionFactory, $ruleChain, $validated, $valueName, $values);
$this->ignoreCharacterSize = $ignoreCharacterSize;
}
Expand All @@ -48,11 +47,10 @@ public function __construct(
protected function validate($value): string
{
if ($this->ignoreCharacterSize) {
/** @var Tin $value */
$value = strtolower($value);
}

/** @phpstan-ignore-next-line todo rewrite char size ignore */
/** @phpstan-ignore-next-line */
return parent::validate($value);
}
}
4 changes: 2 additions & 2 deletions src/Rule/String/StringRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function url(array $requiredComponents = [], array $forbiddenComponents =
*/
public function httpUrl(array $requiredComponents = [], array $forbiddenComponents = []): UrlRule
{
/** @var UrlRule<non-empty-string> */
/** @phpstan-ignore-next-line */
return $this->url($requiredComponents, $forbiddenComponents, ['http', 'https']);
}

Expand All @@ -230,7 +230,7 @@ public function httpUrl(array $requiredComponents = [], array $forbiddenComponen
*/
public function httpsUrl(array $requiredComponents = [], array $forbiddenComponents = []): UrlRule
{
/** @var UrlRule<non-empty-string> */
/** @phpstan-ignore-next-line */
return $this->url($requiredComponents, $forbiddenComponents, ['https']);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Url/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(?Exception $exceptionFactory, RuleChain $ruleChain,
{
parent::__construct($exceptionFactory, $ruleChain, $validated, $valueName);

/** @var RuleChain<array<TComponent>> $ruleChain */
/** @phpstan-ignore-next-line */
$this->key = new Key($exceptionFactory, $ruleChain, $validated, $valueName, $componentName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Url/ParseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(
) {
parent::__construct($exceptionFactory, $ruleChain, $validated, $valueName);

/** @var RuleChain<array<string>> $ruleChain */
/** @phpstan-ignore-next-line */
$this->key = new Key($exceptionFactory, $ruleChain, $validated, $valueName, 'query');
}

Expand Down
5 changes: 2 additions & 3 deletions src/Rule/Url/ParseUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ public function __construct(?Exception $exceptionFactory, RuleChain $ruleChain,

public function scheme(): Scheme
{
/** @var RuleChain<array<non-empty-string, non-empty-string>> $ruleChain */
$ruleChain = $this->ruleChain();
return new Scheme(
$this->exceptionFactory(),
$ruleChain,
/** @phpstan-ignore-next-line */
$this->ruleChain(),
$this->validated(),
$this->valueName().' url scheme',
'scheme'
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Url/Scheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function __construct(
/** @phpstan-ignore-next-line */
new Key(
$exceptionFactory,
/** @phpstan-ignore-next-line */
$ruleChain,
$validated,
$valueName,
Expand All @@ -51,7 +52,6 @@ public function __construct(
*/
public function in(array $values): InRule
{
/** @phpstan-ignore-next-line todo WTF function template */
return new \SimpleAsFuck\Validator\Rule\String\InRule(
$this->exceptionFactory(),
$this->ruleChain(),
Expand Down
15 changes: 7 additions & 8 deletions src/Rule/Url/UrlRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use SimpleAsFuck\Validator\Model\Validated;
use SimpleAsFuck\Validator\Model\ValueMust;
use SimpleAsFuck\Validator\Rule\General\CastString;
use SimpleAsFuck\Validator\Rule\General\Conversion;
use SimpleAsFuck\Validator\Rule\General\Max;
use SimpleAsFuck\Validator\Rule\General\ReadableRule;
use SimpleAsFuck\Validator\Rule\String\StringLength;
Expand Down Expand Up @@ -42,7 +41,9 @@ public function __construct(
) {
parent::__construct($exceptionFactory, $ruleChain, $validated, $valueName);

$this->parseUrl = new ParseUrl(null, new RuleChain(), $this->validated(), $this->valueName(), $requiredComponents, $forbiddenComponents);
/** @var RuleChain<string> $ruleChain */
$ruleChain = new RuleChain();
$this->parseUrl = new ParseUrl(null, $ruleChain, $this->validated(), $this->valueName(), $requiredComponents, $forbiddenComponents);
}

/**
Expand All @@ -51,17 +52,15 @@ public function __construct(
*/
public function max(int $max): Max
{
/** @var RuleChain<string> $ruleChain */
$ruleChain = $this->ruleChain();
/** @var Conversion<string, float|int|string|\Stringable> $stringLength */
$stringLength = new StringLength();
/** @var Max<Tstring, int> */
return new Max(
$this->exceptionFactory(),
$ruleChain,
/** @phpstan-ignore-next-line */
$this->ruleChain(),
$this->validated(),
$this->valueName(),
$stringLength,
/** @phpstan-ignore-next-line */
new StringLength(),
new CastString(),
$max,
'url length'
Expand Down
10 changes: 5 additions & 5 deletions test/Rule/Object/PropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ public function testCustomException(): void
$object = new \stdClass();
$object->property = 0;

/** @var mixed $object */

/** @var RuleChain<object> $ruleChain */
$ruleChain = new RuleChain();
$rule = new \SimpleAsFuck\Validator\Rule\Object\Property(
new UnexpectedValueException(),
new RuleChain(),
$ruleChain,
new Validated($object),
'object',
'property'
);

$this->expectExceptionMessage('object->property must be something not value: 0');
$this->expectExceptionMessage('object->property must be something not value type: int');

$rule
->custom(new class () implements UserDefinedRule {
public function validate($value)
{
throw new ValueMust('be something not value: ' . $value);
throw new ValueMust('be something not value type: ' . gettype($value));
}
})
->notNull()
Expand Down
6 changes: 4 additions & 2 deletions test/Rule/String/CaseInsensitiveInRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ final class CaseInsensitiveInRuleTest extends TestCase
*
* @param non-empty-array<string> $values
*/
public function test(?string $expectedValue, ?string $expectedExceptionMessage, mixed $value, array $values): void
public function test(?string $expectedValue, ?string $expectedExceptionMessage, string $value, array $values): void
{
if ($expectedExceptionMessage !== null) {
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage($expectedExceptionMessage);
}

/** @var RuleChain<string> $ruleChain */
$ruleChain = new RuleChain();
$rule = new CaseInsensitiveInRule(
new UnexpectedValueException(),
new RuleChain(),
$ruleChain,
new Validated($value),
'variable',
$values
Expand Down

0 comments on commit 4d64fb8

Please sign in to comment.