From b2b3eb50ce4754fc9fe533a6e9ddde0d4e3378eb Mon Sep 17 00:00:00 2001 From: Ilario Pierbattista Date: Fri, 12 Jul 2024 12:46:43 +0200 Subject: [PATCH 1/3] Support only PHP >= 8.1 --- .github/workflows/ci.yaml | 2 +- Makefile | 13 +++++-------- docker-compose.yml | 18 ++++++------------ rector.php | 2 +- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 313c2cc..76bd287 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [7.4, 8.0, 8.1] + php: [8.1, 8.2, 8.3] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/Makefile b/Makefile index 6476e3d..5ead79a 100644 --- a/Makefile +++ b/Makefile @@ -9,20 +9,17 @@ help: | xargs -I _ sh -c 'printf "%-40s " _; make _ -nB | (grep -i "^# Help:" || echo "") | tail -1 | sed "s/^# Help: //g"' -.PHONY: run run-php7.4 run-php8.0 run-php8.1 run-php8.2 -run-php7.4: - @# Help: It creates and runs a docker image with PHP 7.4 - docker-compose run --rm php74 bash -c "rm composer.lock || true; composer install --no-interaction; bash" -run-php8.0: - @# Help: It creates and runs a docker image with PHP 8.0 - docker-compose run --rm php80 bash -c "rm composer.lock || true; composer install --no-interaction; bash" +.PHONY: run run-php8.1 run-php8.2 run-php8.1: @# Help: It creates and runs a docker image with PHP 8.1 docker-compose run --rm php81 bash -c "rm composer.lock || true; composer install --no-interaction; bash" run-php8.2: @# Help: It creates and runs a docker image with PHP 8.2 docker-compose run --rm php82 bash -c "rm composer.lock || true; composer install --no-interaction; bash" -run: run-php7.4 +run-php8.3: + @# Help: It creates and runs a docker image with PHP 8.2 + docker-compose run --rm php83 bash -c "rm composer.lock || true; composer install --no-interaction; bash" +run: run-php8.1 @# Help: It creates and runs a docker image with the lowest supported PHP version .PHONY: psalm psalm-update-baseline diff --git a/docker-compose.yml b/docker-compose.yml index 4482d1a..a6aaff7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,32 +1,26 @@ version: "3.8" services: - php74: &base + php81: &base build: context: docker/ args: - PHP_IMAGE: php:7.4 + PHP_IMAGE: php:8.1 XDEBUG: xdebug-3.1.5 volumes: - .:/home/dev/lib tty: true user: dev working_dir: /home/dev/lib - php80: - <<: *base - build: - context: docker/ - args: - PHP_IMAGE: php:8.0 - php81: + php82: <<: *base build: context: docker/ args: - PHP_IMAGE: php:8.1 - php82: + PHP_IMAGE: php:8.2 + php83: <<: *base build: context: docker/ args: - PHP_IMAGE: php:8.2 + PHP_IMAGE: php:8.3 diff --git a/rector.php b/rector.php index ec0d046..e4e11a3 100644 --- a/rector.php +++ b/rector.php @@ -15,6 +15,6 @@ // register a single rule $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_74, + LevelSetList::UP_TO_PHP_81, ]); }; From dffc2ef3e41b91c47d6584613cdb448e3feb2fe5 Mon Sep 17 00:00:00 2001 From: Ilario Pierbattista Date: Fri, 12 Jul 2024 12:51:40 +0200 Subject: [PATCH 2/3] edit rector and makefile --- Makefile | 2 +- rector.php | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 5ead79a..54bf614 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ run-php8.2: @# Help: It creates and runs a docker image with PHP 8.2 docker-compose run --rm php82 bash -c "rm composer.lock || true; composer install --no-interaction; bash" run-php8.3: - @# Help: It creates and runs a docker image with PHP 8.2 + @# Help: It creates and runs a docker image with PHP 8.3 docker-compose run --rm php83 bash -c "rm composer.lock || true; composer install --no-interaction; bash" run: run-php8.1 @# Help: It creates and runs a docker image with the lowest supported PHP version diff --git a/rector.php b/rector.php index e4e11a3..79474b9 100644 --- a/rector.php +++ b/rector.php @@ -2,19 +2,12 @@ declare(strict_types=1); -use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; -use Rector\Set\ValueObject\LevelSetList; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->paths([ +return RectorConfig::configure() + ->withPaths([ __DIR__ . '/src', __DIR__ . '/tests', - ]); - - // register a single rule - $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); - $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_81, - ]); -}; + ]) + ->withPhpSets(php81: true) + ->withTypeCoverageLevel(0); From 3592d74231fb0638e02d85a543a54aec99114fb2 Mon Sep 17 00:00:00 2001 From: Ilario Pierbattista Date: Fri, 12 Jul 2024 12:51:53 +0200 Subject: [PATCH 3/3] apply rector --- composer.json | 2 +- src/Decoder.php | 8 ++------ src/Decoders.php | 4 +--- src/Internal/Arrays/ListOfDecoder.php | 9 ++++----- .../Combinators/ArrayPropsDecoder.php | 6 +----- src/Internal/Combinators/ComposeDecoder.php | 18 +++++++---------- .../Combinators/IntersectionDecoder.php | 18 +++++++---------- src/Internal/Combinators/LiteralDecoder.php | 8 ++------ src/Internal/Combinators/MapDecoder.php | 4 +--- src/Internal/Combinators/UnionDecoder.php | 20 +++++++------------ src/Internal/FunctionUtils.php | 9 ++------- src/Internal/Primitives/UndefinedDecoder.php | 8 +------- src/Internal/Undefined.php | 2 +- .../Useful/DateTimeFromStringDecoder.php | 13 ++++++------ src/Internal/Useful/RegexDecoder.php | 5 +---- .../Useful/StringMatchingRegexDecoder.php | 5 +---- src/Reporters/PathReporter.php | 2 +- src/Reporters/SimplePathReporter.php | 2 +- src/Utils/ConcreteDecoder.php | 4 +--- src/Validation/Context.php | 4 +--- src/Validation/ContextEntry.php | 17 ++-------------- src/Validation/ListOfValidation.php | 2 +- src/Validation/VError.php | 17 ++-------------- src/Validation/Validation.php | 8 ++------ src/Validation/ValidationFailures.php | 6 +----- src/Validation/ValidationSuccess.php | 8 +------- .../DecodeApiResponse/Coordinates.php | 7 +------ .../DecodeApiResponse/OpenWeatherResponse.php | 14 ++----------- tests/examples/DecodeApiResponse/Sys.php | 9 +-------- tests/examples/DecodeApiResponse/Weather.php | 9 +-------- .../examples/DecodePartialPropertiesTest.php | 11 ++-------- tests/examples/DecoderForSumType/A.php | 9 +-------- tests/examples/DecoderForSumType/B.php | 9 +-------- tests/examples/ParseCsv/City.php | 14 ++----------- tests/unit/DecodersTest.php | 5 +---- .../Useful/StringMatchingRegexDecoderTest.php | 2 +- tests/unit/Reporters/ReportersTest.php | 20 +++++-------------- 37 files changed, 76 insertions(+), 242 deletions(-) diff --git a/composer.json b/composer.json index 25ef517..07d31f8 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ } }, "require": { - "php": "^7.4 | ^8.0" + "php": "^8.1" }, "prefer-stable": true, "archive": { diff --git a/src/Decoder.php b/src/Decoder.php index 9b9dfa5..28e4d7f 100644 --- a/src/Decoder.php +++ b/src/Decoder.php @@ -18,19 +18,15 @@ interface Decoder * @psalm-param Context $context * * @psalm-return Validation - * - * @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 - * - * @param mixed $i */ - public function decode($i): Validation; + public function decode(mixed $i): Validation; public function getName(): string; } diff --git a/src/Decoders.php b/src/Decoders.php index d0d41ca..f9e4005 100644 --- a/src/Decoders.php +++ b/src/Decoders.php @@ -203,10 +203,8 @@ public static function transformValidationSuccess(callable $f, Decoder $da): Dec * @psalm-param T $l * * @psalm-return Decoder - * - * @param mixed $l */ - public static function literal($l): Decoder + public static function literal(mixed $l): Decoder { return new LiteralDecoder($l); } diff --git a/src/Internal/Arrays/ListOfDecoder.php b/src/Internal/Arrays/ListOfDecoder.php index 94e31b6..d3045c2 100644 --- a/src/Internal/Arrays/ListOfDecoder.php +++ b/src/Internal/Arrays/ListOfDecoder.php @@ -22,15 +22,14 @@ */ final class ListOfDecoder implements Decoder { - /** @var Decoder */ - private \Facile\PhpCodec\Decoder $elementDecoder; - /** * @psalm-param Decoder $elementDecoder */ - public function __construct(Decoder $elementDecoder) + public function __construct( + /** @var Decoder */ + private readonly \Facile\PhpCodec\Decoder $elementDecoder + ) { - $this->elementDecoder = $elementDecoder; } public function validate($i, Context $context): Validation diff --git a/src/Internal/Combinators/ArrayPropsDecoder.php b/src/Internal/Combinators/ArrayPropsDecoder.php index 015c776..076f99e 100644 --- a/src/Internal/Combinators/ArrayPropsDecoder.php +++ b/src/Internal/Combinators/ArrayPropsDecoder.php @@ -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 diff --git a/src/Internal/Combinators/ComposeDecoder.php b/src/Internal/Combinators/ComposeDecoder.php index 06cfbde..73c5db6 100644 --- a/src/Internal/Combinators/ComposeDecoder.php +++ b/src/Internal/Combinators/ComposeDecoder.php @@ -20,21 +20,17 @@ */ final class ComposeDecoder implements Decoder { - /** @var Decoder */ - private \Facile\PhpCodec\Decoder $db; - /** @var Decoder */ - private \Facile\PhpCodec\Decoder $da; - /** * @psalm-param Decoder $db * @psalm-param Decoder $da */ public function __construct( - Decoder $db, - Decoder $da - ) { - $this->db = $db; - $this->da = $da; + /** @var Decoder */ + private readonly \Facile\PhpCodec\Decoder $db, + /** @var Decoder */ + private readonly \Facile\PhpCodec\Decoder $da + ) + { } /** @@ -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) ); } diff --git a/src/Internal/Combinators/IntersectionDecoder.php b/src/Internal/Combinators/IntersectionDecoder.php index 53cfe01..3737156 100644 --- a/src/Internal/Combinators/IntersectionDecoder.php +++ b/src/Internal/Combinators/IntersectionDecoder.php @@ -24,19 +24,17 @@ */ final class IntersectionDecoder implements Decoder { - /** @var Decoder */ - private \Facile\PhpCodec\Decoder $a; - /** @var Decoder */ - private \Facile\PhpCodec\Decoder $b; - /** * @psalm-param Decoder $a * @psalm-param Decoder $b */ - public function __construct(Decoder $a, Decoder $b) + public function __construct( + /** @var Decoder */ + private readonly \Facile\PhpCodec\Decoder $a, + /** @var Decoder */ + private readonly \Facile\PhpCodec\Decoder $b + ) { - $this->a = $a; - $this->b = $b; } public function validate($i, Context $context): Validation @@ -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 */ diff --git a/src/Internal/Combinators/LiteralDecoder.php b/src/Internal/Combinators/LiteralDecoder.php index 0fe5d8b..6e9e604 100644 --- a/src/Internal/Combinators/LiteralDecoder.php +++ b/src/Internal/Combinators/LiteralDecoder.php @@ -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; } @@ -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}'"; diff --git a/src/Internal/Combinators/MapDecoder.php b/src/Internal/Combinators/MapDecoder.php index 33689c6..6bc7fe8 100644 --- a/src/Internal/Combinators/MapDecoder.php +++ b/src/Internal/Combinators/MapDecoder.php @@ -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 diff --git a/src/Internal/Combinators/UnionDecoder.php b/src/Internal/Combinators/UnionDecoder.php index 05d8f9a..4f8ac7a 100644 --- a/src/Internal/Combinators/UnionDecoder.php +++ b/src/Internal/Combinators/UnionDecoder.php @@ -23,24 +23,18 @@ */ final class UnionDecoder implements Decoder { - /** @var Decoder */ - private \Facile\PhpCodec\Decoder $a; - /** @var Decoder */ - private \Facile\PhpCodec\Decoder $b; - private int $indexBegin; - /** * @psalm-param Decoder $a * @psalm-param Decoder $b */ public function __construct( - Decoder $a, - Decoder $b, - int $indexBegin = 0 - ) { - $this->a = $a; - $this->b = $b; - $this->indexBegin = $indexBegin; + /** @var Decoder */ + private readonly \Facile\PhpCodec\Decoder $a, + /** @var Decoder */ + private readonly \Facile\PhpCodec\Decoder $b, + private readonly int $indexBegin = 0 + ) + { } public function validate($i, Context $context): Validation diff --git a/src/Internal/FunctionUtils.php b/src/Internal/FunctionUtils.php index fb7d76c..c428fa0 100644 --- a/src/Internal/FunctionUtils.php +++ b/src/Internal/FunctionUtils.php @@ -43,10 +43,8 @@ public static function nameFromProps(array $props): string * @psalm-param I $input * * @psalm-return Validation - * - * @param mixed $input */ - public static function standardDecode(Decoder $decoder, $input): Validation + public static function standardDecode(Decoder $decoder, mixed $input): Validation { return $decoder->validate( $input, @@ -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'; diff --git a/src/Internal/Primitives/UndefinedDecoder.php b/src/Internal/Primitives/UndefinedDecoder.php index 3c9dd6b..3355572 100644 --- a/src/Internal/Primitives/UndefinedDecoder.php +++ b/src/Internal/Primitives/UndefinedDecoder.php @@ -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 diff --git a/src/Internal/Undefined.php b/src/Internal/Undefined.php index cf10c3e..4314a31 100644 --- a/src/Internal/Undefined.php +++ b/src/Internal/Undefined.php @@ -4,7 +4,7 @@ namespace Facile\PhpCodec\Internal; -final class Undefined +final class Undefined implements \Stringable { public function __toString(): string { diff --git a/src/Internal/Useful/DateTimeFromStringDecoder.php b/src/Internal/Useful/DateTimeFromStringDecoder.php index 525a108..337a78d 100644 --- a/src/Internal/Useful/DateTimeFromStringDecoder.php +++ b/src/Internal/Useful/DateTimeFromStringDecoder.php @@ -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 diff --git a/src/Internal/Useful/RegexDecoder.php b/src/Internal/Useful/RegexDecoder.php index 1649f4c..2674264 100644 --- a/src/Internal/Useful/RegexDecoder.php +++ b/src/Internal/Useful/RegexDecoder.php @@ -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 diff --git a/src/Internal/Useful/StringMatchingRegexDecoder.php b/src/Internal/Useful/StringMatchingRegexDecoder.php index 733bc34..f90a826 100644 --- a/src/Internal/Useful/StringMatchingRegexDecoder.php +++ b/src/Internal/Useful/StringMatchingRegexDecoder.php @@ -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 diff --git a/src/Reporters/PathReporter.php b/src/Reporters/PathReporter.php index 77d2059..16c5558 100644 --- a/src/Reporters/PathReporter.php +++ b/src/Reporters/PathReporter.php @@ -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!'], diff --git a/src/Reporters/SimplePathReporter.php b/src/Reporters/SimplePathReporter.php index aa1dcf8..f4bd78a 100644 --- a/src/Reporters/SimplePathReporter.php +++ b/src/Reporters/SimplePathReporter.php @@ -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'], diff --git a/src/Utils/ConcreteDecoder.php b/src/Utils/ConcreteDecoder.php index d33a6e6..d218541 100644 --- a/src/Utils/ConcreteDecoder.php +++ b/src/Utils/ConcreteDecoder.php @@ -19,17 +19,15 @@ final class ConcreteDecoder implements Decoder { /** @var callable(I, Context):Validation */ private $validateFunc; - private string $name; /** * @psalm-param callable(I, Context):Validation $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 diff --git a/src/Validation/Context.php b/src/Validation/Context.php index 6ccdb9b..caf071d 100644 --- a/src/Validation/Context.php +++ b/src/Validation/Context.php @@ -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 diff --git a/src/Validation/ContextEntry.php b/src/Validation/ContextEntry.php index de8296c..975d58b 100644 --- a/src/Validation/ContextEntry.php +++ b/src/Validation/ContextEntry.php @@ -8,26 +8,13 @@ final class ContextEntry { - private string $key; - private \Facile\PhpCodec\Decoder $decoder; - /** @var mixed */ - private $actual; - /** * @psalm-param string $key * @psalm-param Decoder $decoder * @psalm-param mixed $actual - * - * @param mixed $actual */ - public function __construct( - string $key, - Decoder $decoder, - $actual - ) { - $this->key = $key; - $this->decoder = $decoder; - $this->actual = $actual; + public function __construct(private readonly string $key, private readonly \Facile\PhpCodec\Decoder $decoder, private readonly mixed $actual) + { } public function getKey(): string diff --git a/src/Validation/ListOfValidation.php b/src/Validation/ListOfValidation.php index 38bef12..006689c 100644 --- a/src/Validation/ListOfValidation.php +++ b/src/Validation/ListOfValidation.php @@ -85,7 +85,7 @@ function (array $es) use (&$errors): void { * * @param mixed $x */ - function ($x) use ($k, &$results): void { + function (mixed $x) use ($k, &$results): void { /** @var K $k */ /** @var array $results */ $results[$k] = $x; diff --git a/src/Validation/VError.php b/src/Validation/VError.php index d2660cd..554c9ff 100644 --- a/src/Validation/VError.php +++ b/src/Validation/VError.php @@ -6,26 +6,13 @@ final class VError { - /** @var mixed */ - private $value; - private \Facile\PhpCodec\Validation\Context $context; - private ?string $message = null; - /** * @psalm-param mixed $value * @psalm-param Context $context * @psalm-param string|null $message - * - * @param mixed $value */ - public function __construct( - $value, - Context $context, - ?string $message = null - ) { - $this->value = $value; - $this->context = $context; - $this->message = $message; + public function __construct(private readonly mixed $value, private readonly \Facile\PhpCodec\Validation\Context $context, private readonly ?string $message = null) + { } /** diff --git a/src/Validation/Validation.php b/src/Validation/Validation.php index 965cf44..ae6436f 100644 --- a/src/Validation/Validation.php +++ b/src/Validation/Validation.php @@ -15,10 +15,8 @@ abstract class Validation * @psalm-param T $a * * @psalm-return ValidationSuccess - * - * @param mixed $a */ - public static function success($a): self + public static function success(mixed $a): self { return new ValidationSuccess($a); } @@ -45,10 +43,8 @@ public static function failures(array $errors): self * @psalm-param string|null $message * * @psalm-return ValidationFailures - * - * @param mixed $value */ - public static function failure($value, Context $context, ?string $message = null): self + public static function failure(mixed $value, Context $context, ?string $message = null): self { return self::failures( [new VError($value, $context, $message)] diff --git a/src/Validation/ValidationFailures.php b/src/Validation/ValidationFailures.php index a28ae54..eb97e25 100644 --- a/src/Validation/ValidationFailures.php +++ b/src/Validation/ValidationFailures.php @@ -11,17 +11,13 @@ */ final class ValidationFailures extends Validation { - /** @var list */ - private array $errors; - /** * @psalm-param list $errors * * @param VError[] $errors */ - public function __construct(array $errors) + public function __construct(private readonly array $errors) { - $this->errors = $errors; } /** diff --git a/src/Validation/ValidationSuccess.php b/src/Validation/ValidationSuccess.php index 8b2d1ac..9a8fa1a 100644 --- a/src/Validation/ValidationSuccess.php +++ b/src/Validation/ValidationSuccess.php @@ -11,17 +11,11 @@ */ final class ValidationSuccess extends Validation { - /** @var A */ - private $value; - /** * @psalm-param A $a - * - * @param mixed $a */ - public function __construct($a) + public function __construct(private readonly mixed $value) { - $this->value = $a; } /** diff --git a/tests/examples/DecodeApiResponse/Coordinates.php b/tests/examples/DecodeApiResponse/Coordinates.php index eff6c6e..ecaa718 100644 --- a/tests/examples/DecodeApiResponse/Coordinates.php +++ b/tests/examples/DecodeApiResponse/Coordinates.php @@ -9,13 +9,8 @@ */ class Coordinates { - private float $longitude; - private float $latitude; - - public function __construct(float $longitude, float $latitude) + public function __construct(private readonly float $longitude, private readonly float $latitude) { - $this->longitude = $longitude; - $this->latitude = $latitude; } public function getLatitude(): float diff --git a/tests/examples/DecodeApiResponse/OpenWeatherResponse.php b/tests/examples/DecodeApiResponse/OpenWeatherResponse.php index ac48f6c..06056ec 100644 --- a/tests/examples/DecodeApiResponse/OpenWeatherResponse.php +++ b/tests/examples/DecodeApiResponse/OpenWeatherResponse.php @@ -9,18 +9,8 @@ */ class OpenWeatherResponse { - private \Examples\Facile\PhpCodec\DecodeApiResponse\Coordinates $coordinates; - private array $weather; - private \Examples\Facile\PhpCodec\DecodeApiResponse\Sys $sys; - - public function __construct( - \Examples\Facile\PhpCodec\DecodeApiResponse\Coordinates $coordinates, - array $weathers, - Sys $sys - ) { - $this->coordinates = $coordinates; - $this->weather = $weathers; - $this->sys = $sys; + public function __construct(private readonly \Examples\Facile\PhpCodec\DecodeApiResponse\Coordinates $coordinates, private readonly array $weather, private readonly \Examples\Facile\PhpCodec\DecodeApiResponse\Sys $sys) + { } public function getCoordinates(): \Examples\Facile\PhpCodec\DecodeApiResponse\Coordinates diff --git a/tests/examples/DecodeApiResponse/Sys.php b/tests/examples/DecodeApiResponse/Sys.php index 4c83ba6..b0bb965 100644 --- a/tests/examples/DecodeApiResponse/Sys.php +++ b/tests/examples/DecodeApiResponse/Sys.php @@ -9,15 +9,8 @@ */ class Sys { - private string $country; - private \DateTimeInterface $sunrise; - private \DateTimeInterface $sunset; - - public function __construct(string $country, \DateTimeInterface $sunrise, \DateTimeInterface $sunset) + public function __construct(private readonly string $country, private readonly \DateTimeInterface $sunrise, private readonly \DateTimeInterface $sunset) { - $this->country = $country; - $this->sunrise = $sunrise; - $this->sunset = $sunset; } public function getCountry(): string diff --git a/tests/examples/DecodeApiResponse/Weather.php b/tests/examples/DecodeApiResponse/Weather.php index 42b902e..e44798c 100644 --- a/tests/examples/DecodeApiResponse/Weather.php +++ b/tests/examples/DecodeApiResponse/Weather.php @@ -9,15 +9,8 @@ */ class Weather { - private int $id; - private string $main; - private string $description; - - public function __construct(int $id, string $main, string $description) + public function __construct(private readonly int $id, private readonly string $main, private readonly string $description) { - $this->id = $id; - $this->main = $main; - $this->description = $description; } public function getId(): int diff --git a/tests/examples/DecodePartialPropertiesTest.php b/tests/examples/DecodePartialPropertiesTest.php index d63886c..741c2b0 100644 --- a/tests/examples/DecodePartialPropertiesTest.php +++ b/tests/examples/DecodePartialPropertiesTest.php @@ -35,15 +35,8 @@ public function test(): void class A { - private string $foo; - private int $bar; - - public function __construct( - string $foo, - int $bar - ) { - $this->foo = $foo; - $this->bar = $bar; + public function __construct(private readonly string $foo, private readonly int $bar) + { } public function getFoo(): string diff --git a/tests/examples/DecoderForSumType/A.php b/tests/examples/DecoderForSumType/A.php index 36570fd..b5e3f9c 100644 --- a/tests/examples/DecoderForSumType/A.php +++ b/tests/examples/DecoderForSumType/A.php @@ -12,15 +12,8 @@ final class A extends P public const SUB_foo = 'foo'; public const SUB_bar = 'bar'; - private string $subType; - private int $propertyA; - private string $propertyB; - - public function __construct(string $subType, int $propertyA, string $propertyB) + public function __construct(private readonly string $subType, private readonly int $propertyA, private readonly string $propertyB) { - $this->subType = $subType; - $this->propertyA = $propertyA; - $this->propertyB = $propertyB; } public function getType(): string diff --git a/tests/examples/DecoderForSumType/B.php b/tests/examples/DecoderForSumType/B.php index 38c9025..e842b5f 100644 --- a/tests/examples/DecoderForSumType/B.php +++ b/tests/examples/DecoderForSumType/B.php @@ -13,15 +13,8 @@ final class B extends P public const CASE_B2 = 2; public const CASE_B3 = 3; - private int $case; - private float $amount; - private bool $flag; - - public function __construct(int $case, float $amount, bool $flag) + public function __construct(private readonly int $case, private readonly float $amount, private readonly bool $flag) { - $this->case = $case; - $this->amount = $amount; - $this->flag = $flag; } public function getType(): string diff --git a/tests/examples/ParseCsv/City.php b/tests/examples/ParseCsv/City.php index c5a90e9..914d00f 100644 --- a/tests/examples/ParseCsv/City.php +++ b/tests/examples/ParseCsv/City.php @@ -6,18 +6,8 @@ class City { - private int $id; - private string $name; - private string $italianLandRegistryCode; - - public function __construct( - int $id, - string $name, - string $italianLandRegistryCode - ) { - $this->id = $id; - $this->name = $name; - $this->italianLandRegistryCode = $italianLandRegistryCode; + public function __construct(private readonly int $id, private readonly string $name, private readonly string $italianLandRegistryCode) + { } public function getId(): int diff --git a/tests/unit/DecodersTest.php b/tests/unit/DecodersTest.php index c288c8a..a302ba9 100644 --- a/tests/unit/DecodersTest.php +++ b/tests/unit/DecodersTest.php @@ -39,11 +39,8 @@ public function testMap(): void class A { - private int $v; - - public function __construct(int $v) + public function __construct(private readonly int $v) { - $this->v = $v; } public function getValue(): int diff --git a/tests/unit/Internal/Useful/StringMatchingRegexDecoderTest.php b/tests/unit/Internal/Useful/StringMatchingRegexDecoderTest.php index ef8e6b1..7091890 100644 --- a/tests/unit/Internal/Useful/StringMatchingRegexDecoderTest.php +++ b/tests/unit/Internal/Useful/StringMatchingRegexDecoderTest.php @@ -46,7 +46,7 @@ public function testDecode(): void Generators::elements(['a', 'b', 'c', 'd', 'e', 'f', 'g']) ) ) - ->then(FunctionUtils::destructureIn(function (int $x, string $a) { + ->then(FunctionUtils::destructureIn(function (int $x, string $a): void { $in = \sprintf('%d%s', $x, $a); self::asserSuccessSameTo( $in, diff --git a/tests/unit/Reporters/ReportersTest.php b/tests/unit/Reporters/ReportersTest.php index 286b955..0665ee8 100644 --- a/tests/unit/Reporters/ReportersTest.php +++ b/tests/unit/Reporters/ReportersTest.php @@ -48,13 +48,11 @@ public function provideReportRootErrors(): array } /** - * @param mixed $value - * * @dataProvider provideReportRootClassError */ public function testReportRootClassError( Reporter $reporter, - $value, + mixed $value, array $expected ): void { $decoder = Decoders::classFromArrayPropsDecoder( @@ -186,11 +184,9 @@ function (array $value) use ($simplePathReporter, $pathReporter, $decoder): void } /** - * @param mixed $value - * * @dataProvider provideNestedArrayPropsReport */ - public function testNestedArrayPropsReport(Reporter $reporter, $value, array $expected): void + public function testNestedArrayPropsReport(Reporter $reporter, mixed $value, array $expected): void { $decoder = Decoders::arrayProps([ 'a' => Decoders::arrayProps([ @@ -258,11 +254,9 @@ public function provideNestedArrayPropsReport(): array } /** - * @param mixed $value - * * @dataProvider provideListOfClassReport */ - public function testListOfClassReport(Reporter $reporter, $value, array $expected): void + public function testListOfClassReport(Reporter $reporter, mixed $value, array $expected): void { $decoder = Decoders::listOf( Decoders::classFromArrayPropsDecoder( @@ -347,11 +341,9 @@ public function provideListOfClassReport(): array } /** - * @param mixed $value - * * @dataProvider provideUnionReport */ - public function testUnionReport(Reporter $reporter, $value, array $expected): void + public function testUnionReport(Reporter $reporter, mixed $value, array $expected): void { $decoder = Decoders::arrayProps([ 'a' => Decoders::union( @@ -435,13 +427,11 @@ public function provideUnionReport(): array } /** - * @param mixed $value - * * @dataProvider provideIntersectionReport */ public function testIntersectionReport( Reporter $reporter, - $value, + mixed $value, array $expected ): void { $d = Decoders::intersection(