diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8b33574..163006b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,10 @@ name: CI -on: [pull_request, push] +on: + pull_request: ~ + push: + branches: + - master jobs: tests: diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 47d4a1d..dc545d1 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -1,6 +1,10 @@ name: Static analysis -on: [pull_request, push] +on: + pull_request: ~ + push: + branches: + - master jobs: job: @@ -10,7 +14,7 @@ jobs: - description: Validate composer.json script: composer validate - description: Code style - script: make cs-fix + script: make cs-check - description: PSalm script: make psalm - description: Type assertions diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..4b3cef4 --- /dev/null +++ b/.php_cs @@ -0,0 +1,29 @@ + false, + 'declare_strict_types' => true, + 'indentation_type' => true, + 'phpdoc_to_comment' => false, + 'phpdoc_trim_consecutive_blank_line_separation' => true, + 'phpdoc_align' => true, + 'nullable_type_declaration_for_default_null_value' => true, + 'lambda_not_used_import' => true, + 'phpdoc_add_missing_param_annotation' => true + ]), +]); + +$finder = PhpCsFixer\Finder::create(); +$autoloadPathProvider = new Facile\CodingStandards\AutoloadPathProvider(); +$finder->in($autoloadPathProvider->getPaths()); + +$config = new PhpCsFixer\Config(); +$config->setRules($rulesProvider->getRules()); +$config->setRiskyAllowed(true); +$config->setUsingCache(false); +$config->setFinder($finder); + +return $config; diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index 7cbfc9f..0000000 --- a/.php_cs.dist +++ /dev/null @@ -1,37 +0,0 @@ - false, - 'declare_strict_types' => true, - 'indentation_type' => true, - 'phpdoc_to_comment' => false, - 'phpdoc_trim_consecutive_blank_line_separation' => true, - 'no_superfluous_phpdoc_tags' => [ - 'allow_mixed' => true, - ], -]; -$rulesProvider = new Facile\CodingStandards\Rules\CompositeRulesProvider([ - new Facile\CodingStandards\Rules\DefaultRulesProvider(), - new Facile\CodingStandards\Rules\ArrayRulesProvider($additionalRules), -]); - -$config = new PhpCsFixer\Config(); -$config->setRules($rulesProvider->getRules()); -$config->setRiskyAllowed(true); - -$finder = PhpCsFixer\Finder::create(); - -/* - * You can set manually these paths: - */ -$autoloadPathProvider = new Facile\CodingStandards\AutoloadPathProvider(); -$finder->in($autoloadPathProvider->getPaths()); - -$config->setFinder($finder); - -return $config; diff --git a/src/Codecs.php b/src/Codecs.php index cdfd267..0647c3b 100644 --- a/src/Codecs.php +++ b/src/Codecs.php @@ -117,8 +117,8 @@ public static function associativeArray(array $props): Codec * @template T * * @param non-empty-array $props - * @param callable(...mixed):T $factory - * @param class-string $fqcn + * @param callable(...mixed):T $factory + * @param class-string $fqcn * * @return Codec */ @@ -145,8 +145,8 @@ public static function classFromArray( * @template E * @template OE * - * @param Codec $a - * @param Codec $b + * @param Codec $a + * @param Codec $b * @param Codec | null $c * @param Codec | null $d * @param Codec | null $e @@ -154,10 +154,10 @@ public static function classFromArray( * // TODO must add type assertions * * @return (func_num_args() is 2 ? Codec - * : (func_num_args() is 3 ? Codec - * : (func_num_args() is 4 ? Codec - * : (func_num_args() is 5 ? Codec : Codec) - * ))) + * : (func_num_args() is 3 ? Codec + * : (func_num_args() is 4 ? Codec + * : (func_num_args() is 5 ? Codec : Codec) + * ))) */ public static function pipe( Codec $a, @@ -185,7 +185,7 @@ public static function pipe( public static function union(Codec $a, Codec $b, Codec ...$others): Codec { // Order is not important, unions should be commutatives - return array_reduce( + return \array_reduce( $others, static function (Codec $carry, Codec $current): Codec { return new UnionType($current, $carry); diff --git a/src/Internal/Arrays/ListRefiner.php b/src/Internal/Arrays/ListRefiner.php index 6a78497..cf04217 100644 --- a/src/Internal/Arrays/ListRefiner.php +++ b/src/Internal/Arrays/ListRefiner.php @@ -25,7 +25,7 @@ public function __construct(Refiner $item) public function is($u): bool { - if (! is_array($u)) { + if (! \is_array($u)) { return false; } diff --git a/src/Internal/Arrays/ListType.php b/src/Internal/Arrays/ListType.php index 9d2c9f3..f27ff9e 100644 --- a/src/Internal/Arrays/ListType.php +++ b/src/Internal/Arrays/ListType.php @@ -36,7 +36,7 @@ public function __construct(Codec $itemCodec) public function validate($i, Context $context): Validation { - if (! is_array($i)) { + if (! \is_array($i)) { return Validation::failure( $i, $context->appendEntries( diff --git a/src/Internal/Arrays/MapRefiner.php b/src/Internal/Arrays/MapRefiner.php index 63d4c5d..96c0de6 100644 --- a/src/Internal/Arrays/MapRefiner.php +++ b/src/Internal/Arrays/MapRefiner.php @@ -17,6 +17,6 @@ class MapRefiner implements Refiner */ public function is($u): bool { - return is_array($u); + return \is_array($u); } } diff --git a/src/Internal/Combinators/ClassFromArray.php b/src/Internal/Combinators/ClassFromArray.php index 26e25a1..155e1a5 100644 --- a/src/Internal/Combinators/ClassFromArray.php +++ b/src/Internal/Combinators/ClassFromArray.php @@ -30,8 +30,8 @@ class ClassFromArray extends Type /** * @param non-empty-array $props - * @param callable(...mixed):T $builder - * @param class-string $fqcn + * @param callable(...mixed):T $builder + * @param class-string $fqcn */ public function __construct( array $props, @@ -39,7 +39,7 @@ public function __construct( string $fqcn ) { parent::__construct( - sprintf('%s(%s)', $fqcn, nameFromProps($props)), + \sprintf('%s(%s)', $fqcn, nameFromProps($props)), new InstanceOfRefiner($fqcn), Encode::identity() ); @@ -53,9 +53,9 @@ public function validate($i, Context $context): Validation $validations = []; foreach ($this->props as $k => $codec) { - $keyName = is_string($k) ? $k : sprintf('[%d]', $k); + $keyName = \is_string($k) ? $k : \sprintf('[%d]', $k); /** @var mixed $value */ - $value = array_key_exists($k, $i) ? $i[$k] : new Undefined(); + $value = \array_key_exists($k, $i) ? $i[$k] : new Undefined(); $validations[] = $codec->validate($value, $context->appendEntries(new ContextEntry($keyName, $codec, $value))); } diff --git a/src/Internal/Combinators/ComposeType.php b/src/Internal/Combinators/ComposeType.php index 510f2e4..00d3811 100644 --- a/src/Internal/Combinators/ComposeType.php +++ b/src/Internal/Combinators/ComposeType.php @@ -31,7 +31,7 @@ class ComposeType extends Type /** * @param Codec $a - * @param Codec $b + * @param Codec $b */ public function __construct( Codec $a, diff --git a/src/Internal/Combinators/UnionType.php b/src/Internal/Combinators/UnionType.php index e0f3b24..e05c1d3 100644 --- a/src/Internal/Combinators/UnionType.php +++ b/src/Internal/Combinators/UnionType.php @@ -31,7 +31,7 @@ public function __construct( Codec $a, Codec $b ) { - $name = sprintf( + $name = \sprintf( '%s | %s', $a->getName(), $b->getName() diff --git a/src/Internal/Experimental/AssociativeArrayRefiner.php b/src/Internal/Experimental/AssociativeArrayRefiner.php index 92ecafd..2b73ad7 100644 --- a/src/Internal/Experimental/AssociativeArrayRefiner.php +++ b/src/Internal/Experimental/AssociativeArrayRefiner.php @@ -24,7 +24,7 @@ public function __construct(array $props) public function is($u): bool { - if (! is_array($u)) { + if (! \is_array($u)) { return false; } diff --git a/src/Internal/PreconditionFailureExcepion.php b/src/Internal/PreconditionFailureExcepion.php index 3957b66..d00c063 100644 --- a/src/Internal/PreconditionFailureExcepion.php +++ b/src/Internal/PreconditionFailureExcepion.php @@ -12,7 +12,7 @@ class PreconditionFailureExcepion extends \LogicException public static function create(string $expectedType, $given): self { return new self( - sprintf( + \sprintf( 'Bad codec composition: expecting input to be of type "%s", given "%s"', $expectedType, typeof($given) diff --git a/src/Internal/Primitives/BoolRefiner.php b/src/Internal/Primitives/BoolRefiner.php index acce13c..bae8cc1 100644 --- a/src/Internal/Primitives/BoolRefiner.php +++ b/src/Internal/Primitives/BoolRefiner.php @@ -13,6 +13,6 @@ class BoolRefiner implements Refiner { public function is($u): bool { - return is_bool($u); + return \is_bool($u); } } diff --git a/src/Internal/Primitives/FloatRefiner.php b/src/Internal/Primitives/FloatRefiner.php index 2a65dc9..1c3a3cd 100644 --- a/src/Internal/Primitives/FloatRefiner.php +++ b/src/Internal/Primitives/FloatRefiner.php @@ -13,6 +13,6 @@ class FloatRefiner implements Refiner { public function is($u): bool { - return is_float($u); + return \is_float($u); } } diff --git a/src/Internal/Primitives/InstanceOfRefiner.php b/src/Internal/Primitives/InstanceOfRefiner.php index 1f4a6b7..7817f4f 100644 --- a/src/Internal/Primitives/InstanceOfRefiner.php +++ b/src/Internal/Primitives/InstanceOfRefiner.php @@ -29,6 +29,6 @@ public function __construct(string $fqcn) */ public function is($u): bool { - return is_a($u, $this->fqcn); + return \is_a($u, $this->fqcn); } } diff --git a/src/Internal/Primitives/IntRefiner.php b/src/Internal/Primitives/IntRefiner.php index 3fee396..ff47d56 100644 --- a/src/Internal/Primitives/IntRefiner.php +++ b/src/Internal/Primitives/IntRefiner.php @@ -13,6 +13,6 @@ class IntRefiner implements Refiner { public function is($u): bool { - return is_int($u); + return \is_int($u); } } diff --git a/src/Internal/Primitives/LiteralType.php b/src/Internal/Primitives/LiteralType.php index cd0ec3f..d0d0762 100644 --- a/src/Internal/Primitives/LiteralType.php +++ b/src/Internal/Primitives/LiteralType.php @@ -39,11 +39,11 @@ public function validate($i, Context $context): Validation */ private static function literalName($x): string { - if (is_string($x)) { + if (\is_string($x)) { return "'$x'"; } - if (is_bool($x)) { + if (\is_bool($x)) { return $x ? 'true' : 'false'; } diff --git a/src/Internal/Primitives/StringRefiner.php b/src/Internal/Primitives/StringRefiner.php index 62ec9bb..aef2fbc 100644 --- a/src/Internal/Primitives/StringRefiner.php +++ b/src/Internal/Primitives/StringRefiner.php @@ -13,6 +13,6 @@ class StringRefiner implements Refiner { public function is($u): bool { - return is_string($u); + return \is_string($u); } } diff --git a/src/Internal/Type.php b/src/Internal/Type.php index 4070b9a..1e0152a 100644 --- a/src/Internal/Type.php +++ b/src/Internal/Type.php @@ -27,7 +27,7 @@ abstract class Type implements Codec private $refine; /** - * @param Refiner $refine + * @param Refiner $refine * @param Encode $encode */ public function __construct( diff --git a/src/Internal/Useful/DateTimeFromIsoStringType.php b/src/Internal/Useful/DateTimeFromIsoStringType.php index f93c3c9..45e5902 100644 --- a/src/Internal/Useful/DateTimeFromIsoStringType.php +++ b/src/Internal/Useful/DateTimeFromIsoStringType.php @@ -26,7 +26,7 @@ public function __construct() public function validate($i, Context $context): Validation { - $r = \DateTime::createFromFormat(DATE_ATOM, $i); + $r = \DateTime::createFromFormat(\DATE_ATOM, $i); if ($r === false) { return Validation::failure($i, $context); diff --git a/src/Internal/Useful/IntFromStringType.php b/src/Internal/Useful/IntFromStringType.php index 71c234b..23e959c 100644 --- a/src/Internal/Useful/IntFromStringType.php +++ b/src/Internal/Useful/IntFromStringType.php @@ -23,14 +23,14 @@ public function __construct() public function validate($i, Context $context): Validation { - return is_numeric($i) + return \is_numeric($i) ? Validation::success((int) $i) : Validation::failure($i, $context); } public function forceCheckPrecondition($i) { - if (! is_string($i)) { + if (! \is_string($i)) { throw PreconditionFailureExcepion::create('string', $i); } diff --git a/src/Internal/Useful/RegexType.php b/src/Internal/Useful/RegexType.php index 8294c2b..9157d4f 100644 --- a/src/Internal/Useful/RegexType.php +++ b/src/Internal/Useful/RegexType.php @@ -22,7 +22,7 @@ class RegexType extends Type public function __construct(string $regex) { parent::__construct( - sprintf('regex(%s)', $regex), + \sprintf('regex(%s)', $regex), new MapRefiner(), Encode::identity() ); @@ -32,7 +32,7 @@ public function __construct(string $regex) public function validate($i, Context $context): Validation { $matches = []; - if (preg_match($this->regex, $i, $matches) === false) { + if (\preg_match($this->regex, $i, $matches) === false) { return Validation::failure($i, $context); } @@ -47,7 +47,7 @@ public function validate($i, Context $context): Validation */ public function forceCheckPrecondition($i) { - if (! is_string($i)) { + if (! \is_string($i)) { throw PreconditionFailureExcepion::create('string', $i); } diff --git a/src/Internal/utils.php b/src/Internal/utils.php index 577d2c8..46c9815 100644 --- a/src/Internal/utils.php +++ b/src/Internal/utils.php @@ -11,20 +11,20 @@ */ function nameFromProps(array $props): string { - return sprintf( + return \sprintf( '{%s}', - implode( + \implode( ', ', - array_map( + \array_map( static function (Codec $t, $k): string { - return sprintf( + return \sprintf( '%s: %s', - is_string($k) ? $k : sprintf('[%d]', $k), + \is_string($k) ? $k : \sprintf('[%d]', $k), $t->getName() ); }, $props, - array_keys($props) + \array_keys($props) ) ) ); @@ -35,9 +35,9 @@ static function (Codec $t, $k): string { */ function typeof($x): string { - if (is_object($x)) { - return get_class($x); + if (\is_object($x)) { + return \get_class($x); } - return gettype($x); + return \gettype($x); } diff --git a/src/PathReporter.php b/src/PathReporter.php index c6a176e..72616ca 100644 --- a/src/PathReporter.php +++ b/src/PathReporter.php @@ -22,7 +22,7 @@ public function report(Validation $validation): array { return Validation::fold( function (array $errors): array { - return array_map( + return \array_map( [self::class, 'getMessage'], $errors ); @@ -37,7 +37,7 @@ function (): array { public static function getMessage(VError $error): string { return $error->getMessage() - ?: sprintf( + ?: \sprintf( 'Invalid value %s supplied to %s', strigify($error->getValue()), self::getContextPath($error->getContext()) @@ -48,9 +48,9 @@ private static function getContextPath(Context $context): string { $parts = []; foreach ($context as $entry) { - $parts[] = sprintf('%s: %s', $entry->getKey(), $entry->getDecoder()->getName()); + $parts[] = \sprintf('%s: %s', $entry->getKey(), $entry->getDecoder()->getName()); } - return implode('/', $parts); + return \implode('/', $parts); } } diff --git a/src/Validation/Context.php b/src/Validation/Context.php index c65c813..2257004 100644 --- a/src/Validation/Context.php +++ b/src/Validation/Context.php @@ -26,7 +26,7 @@ public function __construct( public function appendEntries(ContextEntry ...$entries): self { return new self( - ...array_merge( + ...\array_merge( $this->entries, $entries ) diff --git a/src/Validation/ContextEntry.php b/src/Validation/ContextEntry.php index 522c52b..c40e499 100644 --- a/src/Validation/ContextEntry.php +++ b/src/Validation/ContextEntry.php @@ -17,7 +17,7 @@ class ContextEntry /** * @param Decoder $decoder - * @param mixed $actual + * @param mixed $actual */ public function __construct( string $key, diff --git a/src/Validation/Validation.php b/src/Validation/Validation.php index 19d5f75..b9a4d99 100644 --- a/src/Validation/Validation.php +++ b/src/Validation/Validation.php @@ -50,8 +50,8 @@ public static function failure($value, Context $context, ?string $message = null * @template R * * @param callable(list):R $onFailures - * @param callable(T):R $onSuccess - * @param Validation $v + * @param callable(T):R $onSuccess + * @param Validation $v * * @return R */ @@ -76,7 +76,7 @@ public static function fold(callable $onFailures, callable $onSuccess, self $v) * * @return Validation> */ - public static function sequence(array $validations): Validation + public static function sequence(array $validations): self { $results = []; foreach ($validations as $v) { @@ -99,7 +99,7 @@ public static function sequence(array $validations): Validation * * @return Validation> */ - public static function reduceToSuccessOrAllFailures(array $validations): Validation + public static function reduceToSuccessOrAllFailures(array $validations): self { $results = []; $errors = []; @@ -114,7 +114,7 @@ public static function reduceToSuccessOrAllFailures(array $validations): Validat } if (! empty($errors)) { - return self::failures(array_merge([], ...$errors)); + return self::failures(\array_merge([], ...$errors)); } return self::success($results); @@ -125,11 +125,11 @@ public static function reduceToSuccessOrAllFailures(array $validations): Validat * @template T2 * * @param callable(T1):T2 $f - * @param Validation $v + * @param Validation $v * * @return Validation */ - public static function map(callable $f, Validation $v): Validation + public static function map(callable $f, self $v): self { if ($v instanceof ValidationSuccess) { /** @var ValidationSuccess $v */ @@ -145,11 +145,11 @@ public static function map(callable $f, Validation $v): Validation * @template T2 * * @param callable(T1):Validation $f - * @param Validation $v + * @param Validation $v * * @return Validation */ - public static function bind(callable $f, Validation $v): Validation + public static function bind(callable $f, self $v): self { if ($v instanceof ValidationSuccess) { /** @var ValidationSuccess $v */ diff --git a/src/functions.php b/src/functions.php index fafa8fd..5739eda 100644 --- a/src/functions.php +++ b/src/functions.php @@ -30,17 +30,17 @@ function strigify($x): string return 'null'; } - if (is_string($x)) { + if (\is_string($x)) { return "\"$x\""; } - if (is_array($x)) { - return function_exists('json_encode') - ? json_encode($x) - : serialize($x); + if (\is_array($x)) { + return \function_exists('json_encode') + ? \json_encode($x) + : \serialize($x); } - if (is_bool($x)) { + if (\is_bool($x)) { return $x ? 'true' : 'false'; } diff --git a/tests/examples/CodecForSumtypeTest.php b/tests/examples/CodecForSumtypeTest.php index ac150d5..5f3adf1 100644 --- a/tests/examples/CodecForSumtypeTest.php +++ b/tests/examples/CodecForSumtypeTest.php @@ -59,14 +59,14 @@ function (string $t, int $case, float $amount, bool $flag): internal\B { 'propB' => g\string(), ]) ) - ->then(function ($i) use ($codec) { + ->then(function ($i) use ($codec): void { /** @var ValidationSuccess $result */ $result = $codec->decode($i); self::asserSuccessInstanceOf( internal\A::class, $result, - function (internal\A $a) use ($i) { + function (internal\A $a) use ($i): void { self::assertSame($i['subType'], $a->getSubType()); self::assertSame($i['propA'], $a->getPropertyA()); self::assertSame($i['propB'], $a->getPropertyB()); @@ -83,14 +83,14 @@ function (internal\A $a) use ($i) { 'flag' => g\bool(), ]) ) - ->then(function ($i) use ($codec) { + ->then(function ($i) use ($codec): void { /** @var ValidationSuccess $result */ $result = $codec->decode($i); self::asserSuccessInstanceOf( internal\B::class, $result, - function (internal\B $b) use ($i) { + function (internal\B $b) use ($i): void { self::assertSame($i['case'], $b->getCase()); self::assertEquals($i['amount'], $b->getAmount()); self::assertSame($i['flag'], $b->isFlag()); diff --git a/tests/examples/DecodeApiResponseTest.php b/tests/examples/DecodeApiResponseTest.php index 7ddf614..9526c9a 100644 --- a/tests/examples/DecodeApiResponseTest.php +++ b/tests/examples/DecodeApiResponseTest.php @@ -56,7 +56,7 @@ function (Coordinates $coordinates, array $weathers, Sys $sys): in\OpenWeatherRe in\OpenWeatherResponse::class ); - $result = $codec->decode(json_decode(self::weatherJson(), true)); + $result = $codec->decode(\json_decode(self::weatherJson(), true)); self::asserSuccessInstanceOf( in\OpenWeatherResponse::class, diff --git a/tests/examples/ParseACsvTest.php b/tests/examples/ParseACsvTest.php index c366bb0..2fea8f6 100644 --- a/tests/examples/ParseACsvTest.php +++ b/tests/examples/ParseACsvTest.php @@ -37,12 +37,12 @@ function (int $id, string $name, string $code): in\City { ); $result = $codec->decode( - explode("\n", $simpleCsv) + \explode("\n", $simpleCsv) ); self::asserSuccessAnd( $result, - function (array $cs) { + function (array $cs): void { /** @var in\City[] $cs */ self::assertContainsOnlyInstancesOf(in\City::class, $cs); diff --git a/tests/type-assertions/RefineTypeAssertions.php b/tests/type-assertions/RefineTypeAssertions.php index 97534e8..17be92f 100644 --- a/tests/type-assertions/RefineTypeAssertions.php +++ b/tests/type-assertions/RefineTypeAssertions.php @@ -29,17 +29,17 @@ public function testRefineAssociativeArray(): void $refiner = new MapRefiner(); /** - * @param array $x * @psalm-suppress UnusedParam + * + * @var callable(array):void */ - function assert(array $x): void - { - } + $assert = static function (array $x): void { + }; /** @var mixed $x */ $x = self::mixed(); if ($refiner->is($x)) { - assert($x); + $assert($x); } } diff --git a/tests/unit/BaseTestCase.php b/tests/unit/BaseTestCase.php index eeb44c1..e3d2fcc 100644 --- a/tests/unit/BaseTestCase.php +++ b/tests/unit/BaseTestCase.php @@ -15,8 +15,8 @@ class BaseTestCase extends TestCase * @template T * @template R * - * @param class-string $fqcn - * @param Validation $v + * @param class-string $fqcn + * @param Validation $v * @param null | callable(T):R $thenDo * * @return R | T @@ -24,18 +24,18 @@ class BaseTestCase extends TestCase public static function asserSuccessInstanceOf( string $fqcn, Validation $v, - callable $thenDo = null + ?callable $thenDo = null ) { self::assertInstanceOf( ValidationSuccess::class, $v, - implode("\n", PathReporter::create()->report($v)) + \implode("\n", PathReporter::create()->report($v)) ); /** @var ValidationSuccess $v */ $x = $v->getValue(); self::assertInstanceOf($fqcn, $x); - if (is_callable($thenDo)) { + if (\is_callable($thenDo)) { return $thenDo($x); } @@ -46,7 +46,7 @@ public static function asserSuccessInstanceOf( * @template T * @template R * - * @param T $expected + * @param T $expected * @param Validation $v * * @return T @@ -58,7 +58,7 @@ public static function asserSuccessSameTo( self::assertInstanceOf( ValidationSuccess::class, $v, - implode("\n", PathReporter::create()->report($v)) + \implode("\n", PathReporter::create()->report($v)) ); /** @var ValidationSuccess $v */ @@ -84,7 +84,7 @@ public static function asserSuccessAnd( self::assertInstanceOf( ValidationSuccess::class, $v, - implode("\n", PathReporter::create()->report($v)) + \implode("\n", PathReporter::create()->report($v)) ); /** @var ValidationSuccess $v */ diff --git a/tests/unit/CodecsTest.php b/tests/unit/CodecsTest.php index 5a2f2c9..013c9c8 100644 --- a/tests/unit/CodecsTest.php +++ b/tests/unit/CodecsTest.php @@ -35,7 +35,7 @@ public function testCodec(): void g\bool() ) ) - ->then(function ($x) use ($nullCodec) { + ->then(function ($x) use ($nullCodec): void { self::assertInstanceOf( ValidationFailures::class, $nullCodec->decode($x) @@ -44,7 +44,7 @@ public function testCodec(): void $this ->forAll(g\string()) - ->then(function ($x) { + ->then(function ($x): void { /** @var ValidationSuccess $validation */ $validation = Codecs::string()->decode($x); self::assertInstanceOf(ValidationSuccess::class, $validation); @@ -53,7 +53,7 @@ public function testCodec(): void $this ->forAll(g\int()) - ->then(function ($x) { + ->then(function ($x): void { /** @var ValidationSuccess $validation */ $validation = Codecs::int()->decode($x); self::assertInstanceOf(ValidationSuccess::class, $validation); @@ -81,7 +81,7 @@ function (string $foo, int $bar): in\A { 'bar' => g\int(), ]) ) - ->then(function (array $i) use ($type) { + ->then(function (array $i) use ($type): void { /** @var ValidationSuccess $validation */ $validation = $type->decode($i); @@ -108,7 +108,7 @@ function (string $foo, int $bar): in\A { ), ]) ) - ->then(function (array $i) use ($type) { + ->then(function (array $i) use ($type): void { $validation = $type->decode($i); self::assertInstanceOf(ValidationFailures::class, $validation); @@ -138,11 +138,11 @@ function (string $foo, int $bar): in\A { 'bar' => g\int(), ]) ) - ->then(function (array $i) use ($type) { + ->then(function (array $i) use ($type): void { self::asserSuccessInstanceOf( in\A::class, $type->decode($i), - function (in\A $a) use ($i) { + function (in\A $a) use ($i): void { self::assertSame($i['foo'], $a->getFoo()); self::assertSame($i['bar'], $a->getBar()); } @@ -159,7 +159,7 @@ function (in\A $a) use ($i) { g\constant(null) ) ) - ->then(function ($i) use ($type) { + ->then(function ($i) use ($type): void { $validation = $type->decode($i); self::assertInstanceOf(ValidationSuccess::class, $validation); }); @@ -199,7 +199,7 @@ function (int $size): g { self::asserSuccessAnd( $type->decode($list), function (array $decoded) use ($list): void { - self::assertCount(count($list), $decoded); + self::assertCount(\count($list), $decoded); self::assertContainsOnly(in\A::class, $decoded); } ); diff --git a/tests/unit/Internal/Arrays/ListRefineTest.php b/tests/unit/Internal/Arrays/ListRefineTest.php index f702ec0..4251752 100644 --- a/tests/unit/Internal/Arrays/ListRefineTest.php +++ b/tests/unit/Internal/Arrays/ListRefineTest.php @@ -22,7 +22,7 @@ public function testRefine(): void ->forAll( self::generateList(g\int()) ) - ->then(function ($l) use ($refine) { + ->then(function ($l) use ($refine): void { self::assertTrue($refine->is($l)); }); } diff --git a/tests/unit/Internal/Combinators/UnionRefineTest.php b/tests/unit/Internal/Combinators/UnionRefineTest.php index e9adc07..9a12740 100644 --- a/tests/unit/Internal/Combinators/UnionRefineTest.php +++ b/tests/unit/Internal/Combinators/UnionRefineTest.php @@ -31,7 +31,7 @@ public function testRefineUnion(): void Generator\string() ) ) - ->then(function ($x) use ($mapOrNull, $stringOrInt) { + ->then(function ($x) use ($mapOrNull, $stringOrInt): void { self::assertTrue($stringOrInt->is($x)); self::assertFalse($mapOrNull->is($x)); }); @@ -43,7 +43,7 @@ public function testRefineUnion(): void Generator\string() ) ) - ->then(function ($x) use ($stringOrNull) { + ->then(function ($x) use ($stringOrNull): void { self::assertTrue($stringOrNull->is($x)); }); @@ -54,7 +54,7 @@ public function testRefineUnion(): void Generator\int() ) ) - ->then(function ($x) use ($intOrNull) { + ->then(function ($x) use ($intOrNull): void { self::assertTrue($intOrNull->is($x)); }); @@ -68,7 +68,7 @@ public function testRefineUnion(): void ]) ) ) - ->then(function ($x) use ($stringOrInt, $mapOrNull) { + ->then(function ($x) use ($stringOrInt, $mapOrNull): void { self::assertTrue($mapOrNull->is($x)); self::assertFalse($stringOrInt->is($x)); }); diff --git a/tests/unit/Internal/Combinators/UnionTypeTest.php b/tests/unit/Internal/Combinators/UnionTypeTest.php index 116e878..74af082 100644 --- a/tests/unit/Internal/Combinators/UnionTypeTest.php +++ b/tests/unit/Internal/Combinators/UnionTypeTest.php @@ -11,7 +11,7 @@ class UnionTypeTest extends TestCase { - public function testValidate() + public function testValidate(): void { $unionOfTwo = new UnionType(Codecs::null(), Codecs::string()); diff --git a/tests/unit/Internal/Primitives/BoolRefineTest.php b/tests/unit/Internal/Primitives/BoolRefineTest.php index 4509b34..ba59c7e 100644 --- a/tests/unit/Internal/Primitives/BoolRefineTest.php +++ b/tests/unit/Internal/Primitives/BoolRefineTest.php @@ -24,7 +24,7 @@ public function test(): void ->forAll( g\oneOf(g\string(), g\int(), g\float(), g\date()) ) - ->then(function ($x) use ($refine) { + ->then(function ($x) use ($refine): void { self::assertFalse($refine->is($x)); }); } diff --git a/tests/unit/Internal/Primitives/BoolTypeTest.php b/tests/unit/Internal/Primitives/BoolTypeTest.php index 06bbf0e..bd27ede 100644 --- a/tests/unit/Internal/Primitives/BoolTypeTest.php +++ b/tests/unit/Internal/Primitives/BoolTypeTest.php @@ -25,7 +25,7 @@ public function testValidate(): void ->forAll( g\oneOf(g\string(), g\int(), g\float(), g\date(), g\constant(null)) ) - ->then(function ($x) use ($type) { + ->then(function ($x) use ($type): void { self::assertInstanceOf( ValidationFailures::class, $type->decode($x) diff --git a/tests/unit/Internal/Primitives/IntRefineTest.php b/tests/unit/Internal/Primitives/IntRefineTest.php index b720446..1309ac9 100644 --- a/tests/unit/Internal/Primitives/IntRefineTest.php +++ b/tests/unit/Internal/Primitives/IntRefineTest.php @@ -21,7 +21,7 @@ public function testRefiner(): void ->forAll( Generator\int() ) - ->then(function ($i) use ($refiner) { + ->then(function ($i) use ($refiner): void { self::assertTrue($refiner->is($i)); }); @@ -34,7 +34,7 @@ public function testRefiner(): void Generator\bool() ) ) - ->then(function ($i) use ($refiner) { + ->then(function ($i) use ($refiner): void { self::assertFalse($refiner->is($i)); }); } diff --git a/tests/unit/Internal/Useful/DateTimeFromIsoStringTypeTest.php b/tests/unit/Internal/Useful/DateTimeFromIsoStringTypeTest.php index d1eef4e..9037063 100644 --- a/tests/unit/Internal/Useful/DateTimeFromIsoStringTypeTest.php +++ b/tests/unit/Internal/Useful/DateTimeFromIsoStringTypeTest.php @@ -25,10 +25,10 @@ public function test(): void ->forAll( g\date() ) - ->then(function (\DateTimeInterface $date) use ($codec) { + ->then(function (\DateTimeInterface $date) use ($codec): void { self::asserSuccessInstanceOf( \DateTimeInterface::class, - $codec->decode($date->format(DATE_ATOM)) + $codec->decode($date->format(\DATE_ATOM)) ); }); } diff --git a/tests/unit/PathReporterTest.php b/tests/unit/PathReporterTest.php index 6f6e827..f9c4643 100644 --- a/tests/unit/PathReporterTest.php +++ b/tests/unit/PathReporterTest.php @@ -59,7 +59,7 @@ function (string $a, int $b, float $c): in\A { g\oneOf(g\string(), g\float(), g\bool(), g\constant(null)), g\oneOf(g\string(), g\int(), g\bool(), g\constant(null)) ) - ->then(function ($a, $b, $c) use ($type, $reporter) { + ->then(function ($a, $b, $c) use ($type, $reporter): void { $errors = $reporter->report( $type->decode([ 'a' => $a, @@ -70,9 +70,9 @@ function (string $a, int $b, float $c): in\A { self::assertEquals( [ - sprintf('Invalid value %s supplied to : Tests\Facile\PhpCodec\PathReporterTest\A({a: string, b: int, c: float})/a: string', strigify($a)), - sprintf('Invalid value %s supplied to : Tests\Facile\PhpCodec\PathReporterTest\A({a: string, b: int, c: float})/b: int', strigify($b)), - sprintf('Invalid value %s supplied to : Tests\Facile\PhpCodec\PathReporterTest\A({a: string, b: int, c: float})/c: float', strigify($c)), + \sprintf('Invalid value %s supplied to : Tests\Facile\PhpCodec\PathReporterTest\A({a: string, b: int, c: float})/a: string', strigify($a)), + \sprintf('Invalid value %s supplied to : Tests\Facile\PhpCodec\PathReporterTest\A({a: string, b: int, c: float})/b: int', strigify($b)), + \sprintf('Invalid value %s supplied to : Tests\Facile\PhpCodec\PathReporterTest\A({a: string, b: int, c: float})/c: float', strigify($c)), ], $errors );