Skip to content

Commit

Permalink
Converted phpstan doc comments to generic
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wright <tom@inflatablecookie.com>
  • Loading branch information
betterthanclay committed Sep 26, 2023
1 parent 22074eb commit d73772a
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Converted phpstan doc comments to generic
* Migrated to use effigy in CI workflow
* Fixed PHP8.1 testing
* Updated getChildValues() return signature
Expand Down
14 changes: 7 additions & 7 deletions src/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
interface Constraint
{
/**
* @phpstan-param Processor<TValue> $processor
* @param Processor<TValue> $processor
*/
public function __construct(Processor $processor);

Expand All @@ -32,12 +32,12 @@ public function getName(): string;
public function getWeight(): int;

/**
* @phpstan-return Processor<TValue>
* @return Processor<TValue>
*/
public function getProcessor(): Processor;

/**
* @phpstan-param TParam $param
* @param TParam $param
* @return $this
*/
public function setParameter(mixed $param): static;
Expand All @@ -46,14 +46,14 @@ public function getParameter(): mixed;
public function prepareValue(mixed $value): mixed;

/**
* @phpstan-param TValue $value
* @phpstan-return TValue|null
* @param TValue $value
* @return TValue|null
*/
public function alterValue(mixed $value): mixed;

/**
* @phpstan-param TValue|null $value
* @phpstan-return Generator<int, Error|null, mixed, bool>
* @param TValue|null $value
* @return Generator<int, Error|null, mixed, bool>
*/
public function validate(mixed $value): Generator;
}
2 changes: 1 addition & 1 deletion src/Constraint/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class Processor implements Constraint
{
/**
* @phpstan-use ConstraintTrait<TValue, TValue>
* @use ConstraintTrait<TValue, TValue>
*/
use ConstraintTrait;

Expand Down
8 changes: 4 additions & 4 deletions src/ConstraintTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
trait ConstraintTrait
{
/**
* @phpstan-var Processor<TValue>
* @var Processor<TValue>
*/
protected Processor $processor;

/**
* @phpstan-param Processor<TValue> $processor
* @param Processor<TValue> $processor
*/
public function __construct(Processor $processor)
{
Expand Down Expand Up @@ -62,7 +62,7 @@ public function getProcessor(): Processor
}

/**
* @phpstan-param TParam $param
* @param TParam $param
* @return $this
*/
public function setParameter(mixed $param): static
Expand All @@ -86,7 +86,7 @@ public function alterValue(mixed $value): mixed
}

/**
* @phpstan-param TValue $value
* @param TValue $value
*/
public function validate(mixed $value): Generator
{
Expand Down
12 changes: 6 additions & 6 deletions src/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public function prepareValue(mixed $value): mixed;
/**
* Apply value processing before validation
*
* @phpstan-param TOutput $value
* @phpstan-return TOutput|null
* @param TOutput $value
* @return TOutput|null
*/
public function alterValue(mixed $value): mixed;

/**
* Coerce input to output type or null
*
* @phpstan-return TOutput|null
* @return TOutput|null
*/
public function coerce(mixed $value): mixed;

Expand All @@ -71,23 +71,23 @@ public function getDefaultConstraints(): array;


/**
* @phpstan-return array<string, Constraint<mixed, TOutput>>
* @return array<string, Constraint<mixed, TOutput>>
*/
public function prepareConstraints(): array;


/**
* Test constraints and yield errors in sequence
*
* @phpstan-param TOutput|null $value
* @param TOutput|null $value
* @return Generator<Error|null>
*/
public function validate(mixed $value): Generator;

/**
* Test type and yield errors in sequence
*
* @phpstan-param TOutput|null $value
* @param TOutput|null $value
* @return Generator<Error|null>
*/
public function validateType(mixed $value): Generator;
Expand Down
6 changes: 3 additions & 3 deletions src/Provider/DirectContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface DirectContext extends Provider
{
/**
* @template TInput
* @phpstan-param TInput $value
* @param TInput $value
* @param array<string, mixed>|Closure|null $setup
*/
public function make(
Expand All @@ -29,7 +29,7 @@ public function make(

/**
* @template TInput
* @phpstan-param TInput $value
* @param TInput $value
* @param array<string, mixed>|Closure|null $setup
* @return Result<mixed>
*/
Expand All @@ -41,7 +41,7 @@ public function validate(

/**
* @template TInput
* @phpstan-param TInput $value
* @param TInput $value
* @param array<string, mixed>|Closure|null $setup
*/
public function is(
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/MultiContextTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function sanitize(
}

/**
* @phpstan-return TValue|null
* @return TValue|null
*/
abstract protected function getValue(
int|string $key
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/SingleContextTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function sanitize(): Sanitizer
}

/**
* @phpstan-return TValue
* @return TValue
*/
abstract protected function getValue(): mixed;
}
2 changes: 1 addition & 1 deletion src/Sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function validate(
* Load processor for value
*
* @param array<string, mixed>|Closure|null $setup
* @phpstan-return Processor<mixed>
* @return Processor<mixed>
*/
public function loadProcessor(
string $type,
Expand Down
6 changes: 3 additions & 3 deletions src/Validate/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class Error
protected array $params = [];

/**
* @phpstan-var Constraint<mixed, mixed>
* @var Constraint<mixed, mixed>
*/
protected Constraint $constraint;
protected string $constraintKey;

/**
* @phpstan-param Constraint<mixed, mixed>|Processor<mixed> $constraint
* @param Constraint<mixed, mixed>|Processor<mixed> $constraint
* @param array<string, mixed> $params
*/
public function __construct(
Expand Down Expand Up @@ -61,7 +61,7 @@ public function getId(): string
}

/**
* @phpstan-return Constraint<mixed, mixed>
* @return Constraint<mixed, mixed>
*/
public function getConstraint(): Constraint
{
Expand Down
12 changes: 6 additions & 6 deletions src/Validate/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
class Result
{
/**
* @phpstan-var TValue|null
* @var TValue|null
*/
protected mixed $value = null;

/**
* @phpstan-var Processor<TValue>
* @var Processor<TValue>
*/
protected Processor $processor;

Expand All @@ -34,7 +34,7 @@ class Result
/**
* Init with processor
*
* @phpstan-param Processor<TValue> $processor
* @param Processor<TValue> $processor
*/
public function __construct(Processor $processor)
{
Expand All @@ -45,7 +45,7 @@ public function __construct(Processor $processor)
/**
* Set value
*
* @phpstan-param TValue $value
* @param TValue $value
* @return $this
*/
public function setValue(mixed $value): static
Expand All @@ -58,7 +58,7 @@ public function setValue(mixed $value): static
/**
* Get value
*
* @phpstan-return TValue|null
* @return TValue|null
*/
public function getValue(): mixed
{
Expand All @@ -68,7 +68,7 @@ public function getValue(): mixed
/**
* Get processor
*
* @phpstan-return Processor<TValue>
* @return Processor<TValue>
*/
public function getProcessor(): Processor
{
Expand Down
6 changes: 3 additions & 3 deletions tests/AnalyzeMixedContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AnalyzeMixedContextProvider implements MixedContext
use MixedContextTrait;

/**
* @phpstan-var TValue
* @var TValue
*/
protected mixed $value;

Expand All @@ -35,15 +35,15 @@ public function __construct(mixed $value)
}

/**
* @phpstan-return TValue
* @return TValue
*/
public function getValue(): mixed
{
return $this->value;
}

/**
* @phpstan-return array<TValue>
* @return array<TValue>
*/
public function getChildValues(): array
{
Expand Down
4 changes: 2 additions & 2 deletions tests/AnalyzeMultiContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AnalyzeMultiContextProvider implements MultiContext
use MultiContextTrait;

/**
* @phpstan-var array<string, TValue>
* @var array<string, TValue>
*/
protected array $values;

Expand All @@ -37,7 +37,7 @@ public function __construct(
}

/**
* @phpstan-return TValue|null
* @return TValue|null
*/
public function getValue(
int|string $key
Expand Down
4 changes: 2 additions & 2 deletions tests/AnalyzeSingleContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AnalyzeSingleContextProvider implements SingleContext
use SingleContextTrait;

/**
* @phpstan-var TValue
* @var TValue
*/
protected mixed $value;

Expand All @@ -35,7 +35,7 @@ public function __construct(mixed $value)
}

/**
* @phpstan-return TValue
* @return TValue
*/
public function getValue(): mixed
{
Expand Down
2 changes: 1 addition & 1 deletion tests/SanitizerImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function validate(
* Load processor for value
*
* @param array<string, mixed>|Closure|null $setup
* @phpstan-return Processor<mixed>
* @return Processor<mixed>
*/
public function loadProcessor(
string $type,
Expand Down

0 comments on commit d73772a

Please sign in to comment.