Skip to content

Commit

Permalink
apply rector
Browse files Browse the repository at this point in the history
  • Loading branch information
ilario-pierbattista committed Jul 12, 2024
1 parent dffc2ef commit 3592d74
Show file tree
Hide file tree
Showing 37 changed files with 76 additions and 242 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
},
"require": {
"php": "^7.4 | ^8.0"
"php": "^8.1"
},
"prefer-stable": true,
"archive": {
Expand Down
8 changes: 2 additions & 6 deletions src/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@ interface Decoder
* @psalm-param Context $context
*
* @psalm-return Validation<A>
*
* @param mixed $i
*/
public function validate($i, Context $context): Validation;
public function validate(mixed $i, Context $context): Validation;

/**
* @psalm-param I $i
*
* @psalm-return Validation<A>
*
* @param mixed $i
*/
public function decode($i): Validation;
public function decode(mixed $i): Validation;

public function getName(): string;
}
4 changes: 1 addition & 3 deletions src/Decoders.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ public static function transformValidationSuccess(callable $f, Decoder $da): Dec
* @psalm-param T $l
*
* @psalm-return Decoder<mixed, T>
*
* @param mixed $l
*/
public static function literal($l): Decoder
public static function literal(mixed $l): Decoder
{
return new LiteralDecoder($l);
}
Expand Down
9 changes: 4 additions & 5 deletions src/Internal/Arrays/ListOfDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
*/
final class ListOfDecoder implements Decoder
{
/** @var Decoder<IT, T> */
private \Facile\PhpCodec\Decoder $elementDecoder;

/**
* @psalm-param Decoder<IT, T> $elementDecoder
*/
public function __construct(Decoder $elementDecoder)
public function __construct(
/** @var Decoder<IT, T> */
private readonly \Facile\PhpCodec\Decoder $elementDecoder
)
{
$this->elementDecoder = $elementDecoder;
}

public function validate($i, Context $context): Validation
Expand Down
6 changes: 1 addition & 5 deletions src/Internal/Combinators/ArrayPropsDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@
*/
final class ArrayPropsDecoder implements Decoder
{
/** @var PD */
private array $props;

/**
* @psalm-param PD $props
*/
public function __construct(array $props)
public function __construct(private readonly array $props)
{
$this->props = $props;
}

public function validate($i, Context $context): Validation
Expand Down
18 changes: 7 additions & 11 deletions src/Internal/Combinators/ComposeDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@
*/
final class ComposeDecoder implements Decoder
{
/** @var Decoder<A, B> */
private \Facile\PhpCodec\Decoder $db;
/** @var Decoder<IA, A> */
private \Facile\PhpCodec\Decoder $da;

/**
* @psalm-param Decoder<A, B> $db
* @psalm-param Decoder<IA, A> $da
*/
public function __construct(
Decoder $db,
Decoder $da
) {
$this->db = $db;
$this->da = $da;
/** @var Decoder<A, B> */
private readonly \Facile\PhpCodec\Decoder $db,
/** @var Decoder<IA, A> */
private readonly \Facile\PhpCodec\Decoder $da
)
{
}

/**
Expand All @@ -53,7 +49,7 @@ public function validate($i, Context $context): Validation
*
* @param mixed $aValue
*/
fn($aValue): Validation => $this->db->validate($aValue, $context),
fn(mixed $aValue): Validation => $this->db->validate($aValue, $context),
$this->da->validate($i, $context)
);
}
Expand Down
18 changes: 7 additions & 11 deletions src/Internal/Combinators/IntersectionDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@
*/
final class IntersectionDecoder implements Decoder
{
/** @var Decoder<IA, A> */
private \Facile\PhpCodec\Decoder $a;
/** @var Decoder<IB, B> */
private \Facile\PhpCodec\Decoder $b;

/**
* @psalm-param Decoder<IA, A> $a
* @psalm-param Decoder<IB, B> $b
*/
public function __construct(Decoder $a, Decoder $b)
public function __construct(
/** @var Decoder<IA, A> */
private readonly \Facile\PhpCodec\Decoder $a,
/** @var Decoder<IB, B> */
private readonly \Facile\PhpCodec\Decoder $b
)
{
$this->a = $a;
$this->b = $b;
}

public function validate($i, Context $context): Validation
Expand Down Expand Up @@ -97,12 +95,10 @@ public function getName(): string
*
* @psalm-return T1&T2
*
* @param mixed $a
* @param mixed $b
*
* @return array|object
*/
private static function intersectResults($a, $b)
private static function intersectResults(mixed $a, mixed $b)
{
if (\is_array($a) && \is_array($b)) {
/** @var T1&T2 */
Expand Down
8 changes: 2 additions & 6 deletions src/Internal/Combinators/LiteralDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ final class LiteralDecoder implements Decoder

/**
* @psalm-param T $literal
*
* @param mixed $literal
*/
public function __construct($literal)
public function __construct(mixed $literal)
{
$this->literal = $literal;
}
Expand All @@ -59,10 +57,8 @@ public function getName(): string

/**
* @psalm-param literable $x
*
* @param mixed $x
*/
private static function literalName($x): string
private static function literalName(mixed $x): string
{
if (\is_string($x)) {
return "'{$x}'";
Expand Down
4 changes: 1 addition & 3 deletions src/Internal/Combinators/MapDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ final class MapDecoder implements Decoder
{
/** @var callable(A):B */
private $f;
private string $name;

/**
* @psalm-param callable(A):B $f
*/
public function __construct(callable $f, string $name = 'map')
public function __construct(callable $f, private readonly string $name = 'map')
{
$this->f = $f;
$this->name = $name;
}

public function validate($i, Context $context): Validation
Expand Down
20 changes: 7 additions & 13 deletions src/Internal/Combinators/UnionDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,18 @@
*/
final class UnionDecoder implements Decoder
{
/** @var Decoder<IA, A> */
private \Facile\PhpCodec\Decoder $a;
/** @var Decoder<IB, B> */
private \Facile\PhpCodec\Decoder $b;
private int $indexBegin;

/**
* @psalm-param Decoder<IA, A> $a
* @psalm-param Decoder<IB, B> $b
*/
public function __construct(
Decoder $a,
Decoder $b,
int $indexBegin = 0
) {
$this->a = $a;
$this->b = $b;
$this->indexBegin = $indexBegin;
/** @var Decoder<IA, A> */
private readonly \Facile\PhpCodec\Decoder $a,
/** @var Decoder<IB, B> */
private readonly \Facile\PhpCodec\Decoder $b,
private readonly int $indexBegin = 0
)
{
}

public function validate($i, Context $context): Validation
Expand Down
9 changes: 2 additions & 7 deletions src/Internal/FunctionUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public static function nameFromProps(array $props): string
* @psalm-param I $input
*
* @psalm-return Validation<A>
*
* @param mixed $input
*/
public static function standardDecode(Decoder $decoder, $input): Validation
public static function standardDecode(Decoder $decoder, mixed $input): Validation
{
return $decoder->validate(
$input,
Expand All @@ -69,10 +67,7 @@ public static function destructureIn(callable $f): callable
return fn(array $params) => $f(...$params);
}

/**
* @param mixed $x
*/
public static function strigify($x): string
public static function strigify(mixed $x): string
{
if ($x === null) {
return 'null';
Expand Down
8 changes: 1 addition & 7 deletions src/Internal/Primitives/UndefinedDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@
*/
final class UndefinedDecoder implements Decoder
{
/** @var U */
private $default;

/**
* @psalm-param U $default
*
* @param mixed $default
*/
public function __construct($default)
public function __construct(private readonly mixed $default)
{
$this->default = $default;
}

public function validate($i, Context $context): Validation
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Undefined.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Facile\PhpCodec\Internal;

final class Undefined
final class Undefined implements \Stringable
{
public function __toString(): string
{
Expand Down
13 changes: 6 additions & 7 deletions src/Internal/Useful/DateTimeFromStringDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
*/
final class DateTimeFromStringDecoder implements Decoder
{
/**
* @psalm-readonly
*/
private string $format;

public function __construct(string $format = \DATE_ATOM)
public function __construct(
/**
* @psalm-readonly
*/
private readonly string $format = \DATE_ATOM
)
{
$this->format = $format;
}

public function validate($i, Context $context): Validation
Expand Down
5 changes: 1 addition & 4 deletions src/Internal/Useful/RegexDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
*/
final class RegexDecoder implements Decoder
{
private string $regex;

public function __construct(string $regex)
public function __construct(private readonly string $regex)
{
$this->regex = $regex;
}

public function validate($i, Context $context): Validation
Expand Down
5 changes: 1 addition & 4 deletions src/Internal/Useful/StringMatchingRegexDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
*/
final class StringMatchingRegexDecoder implements Decoder
{
private string $regex;

public function __construct(string $regex)
public function __construct(private readonly string $regex)
{
$this->regex = $regex;
}

public function validate($i, Context $context): Validation
Expand Down
2 changes: 1 addition & 1 deletion src/Reporters/PathReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function report(Validation $validation): array
{
return Validation::fold(
fn(array $errors): array => \array_map(
[self::class, 'getMessage'],
self::getMessage(...),
$errors
),
fn(): array => ['No errors!'],
Expand Down
2 changes: 1 addition & 1 deletion src/Reporters/SimplePathReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function report(Validation $validation): array
{
return Validation::fold(
static fn(array $errors): array => array_map(
[self::class, 'getMessage'],
self::getMessage(...),
$errors
),
static fn(): array => ['No errors'],
Expand Down
4 changes: 1 addition & 3 deletions src/Utils/ConcreteDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ final class ConcreteDecoder implements Decoder
{
/** @var callable(I, Context):Validation<A> */
private $validateFunc;
private string $name;

/**
* @psalm-param callable(I, Context):Validation<A> $validate
*/
public function __construct(
callable $validate,
string $name
private readonly string $name
) {
$this->validateFunc = $validate;
$this->name = $name;
}

public function validate($i, Context $context): Validation
Expand Down
4 changes: 1 addition & 3 deletions src/Validation/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ final class Context implements \Iterator
/** @var ContextEntry[] */
private array $entries;
private int $currentIndex = 0;
private \Facile\PhpCodec\Decoder $decoder;

/**
* @psalm-param Decoder $decoder
* @psalm-param ContextEntry ...$entries
*/
public function __construct(
Decoder $decoder,
private readonly \Facile\PhpCodec\Decoder $decoder,
ContextEntry ...$entries
) {
$this->entries = $entries;
$this->decoder = $decoder;
}

public function appendEntries(ContextEntry ...$entries): self
Expand Down
Loading

0 comments on commit 3592d74

Please sign in to comment.