diff --git a/composer.json b/composer.json index a5ac50a..7f0ed21 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "thecodingmachine/safe": "^2.2" }, "require-dev": { - "doctrine/coding-standard": "^9", + "doctrine/coding-standard": "^10", "ergebnis/composer-normalize": "^2.27", "infection/infection": "^0.26", "phpstan/extension-installer": "^1.1", diff --git a/src/Exception/NoResponse.php b/src/Exception/NoResponse.php index ff4967a..ed284c7 100644 --- a/src/Exception/NoResponse.php +++ b/src/Exception/NoResponse.php @@ -12,7 +12,7 @@ class NoResponse extends Exception { protected string $method; protected string $path; - protected ?string $statusCode = null; + protected string|null $statusCode = null; public static function forPathAndMethod(string $path, string $method): self { diff --git a/src/OpenAPIFaker.php b/src/OpenAPIFaker.php index a99b6a2..37da04d 100644 --- a/src/OpenAPIFaker.php +++ b/src/OpenAPIFaker.php @@ -66,7 +66,7 @@ public static function createFromYaml(string $yaml): self public function mockRequest( string $path, string $method, - string $contentType = 'application/json' + string $contentType = 'application/json', ): mixed { $operation = $this->findOperation($path, $method); @@ -93,7 +93,7 @@ public function mockResponse( string $path, string $method, string $statusCode = '200', - string $contentType = 'application/json' + string $contentType = 'application/json', ): mixed { $operation = $this->findOperation($path, $method); @@ -119,9 +119,7 @@ public function mockResponse( return (new SchemaFaker($content->schema, $this->options))->generate(); } - /** - * @throws Exception - */ + /** @throws Exception */ public function mockComponentSchema(string $schemaName): mixed { if ($this->openAPISchema->components === null) { @@ -138,9 +136,7 @@ public function mockComponentSchema(string $schemaName): mixed return (new SchemaFaker($schema, $this->options))->generate(); } - /** - * @param array{minItems?:?int, maxItems?:?int, alwaysFakeOptionals?:bool} $options - */ + /** @param array{minItems?:?int, maxItems?:?int, alwaysFakeOptionals?:bool} $options */ public function setOptions(array $options): self { foreach ($options as $key => $value) { @@ -154,15 +150,13 @@ public function setOptions(array $options): self return $this; } - /** - * @throws NoPath - */ + /** @throws NoPath */ private function findOperation(string $path, string $method): Operation { try { $operation = (new LeagueOpenAPI\SpecFinder($this->openAPISchema)) ->findOperationSpec(new LeagueOpenAPI\OperationAddress($path, strtolower($method))); - } catch (LeagueOpenAPI\Exception\NoPath $e) { + } catch (LeagueOpenAPI\Exception\NoPath) { throw NoPath::forPathAndMethod($path, $method); } diff --git a/src/Options.php b/src/Options.php index 4f6afaa..ada7158 100644 --- a/src/Options.php +++ b/src/Options.php @@ -6,8 +6,8 @@ final class Options { - private ?int $minItems = null; - private ?int $maxItems = null; + private int|null $minItems = null; + private int|null $maxItems = null; private bool $alwaysFakeOptionals = false; public function setMinItems(int $minItems): Options @@ -31,12 +31,12 @@ public function setAlwaysFakeOptionals(bool $alwaysFakeOptionals): self return $this; } - public function getMinItems(): ?int + public function getMinItems(): int|null { return $this->minItems; } - public function getMaxItems(): ?int + public function getMaxItems(): int|null { return $this->maxItems; } diff --git a/src/SchemaFaker/ArrayFaker.php b/src/SchemaFaker/ArrayFaker.php index cb87161..d6b2a76 100644 --- a/src/SchemaFaker/ArrayFaker.php +++ b/src/SchemaFaker/ArrayFaker.php @@ -15,14 +15,10 @@ use const SORT_REGULAR; use const SORT_STRING; -/** - * @internal - */ +/** @internal */ final class ArrayFaker { - /** - * @return array - */ + /** @return array */ public static function generate(Schema $schema, Options $options): array { $minimum = $schema->minItems ?? 0; diff --git a/src/SchemaFaker/BooleanFaker.php b/src/SchemaFaker/BooleanFaker.php index 91c7aa0..02b5d71 100644 --- a/src/SchemaFaker/BooleanFaker.php +++ b/src/SchemaFaker/BooleanFaker.php @@ -9,9 +9,7 @@ use function random_int; -/** - * @internal - */ +/** @internal */ final class BooleanFaker { public static function generate(Schema $schema): bool diff --git a/src/SchemaFaker/NumberFaker.php b/src/SchemaFaker/NumberFaker.php index 7075589..e413816 100644 --- a/src/SchemaFaker/NumberFaker.php +++ b/src/SchemaFaker/NumberFaker.php @@ -9,9 +9,7 @@ use function mt_getrandmax; -/** - * @internal - */ +/** @internal */ final class NumberFaker { public static function generate(Schema $schema): int|float diff --git a/src/SchemaFaker/ObjectFaker.php b/src/SchemaFaker/ObjectFaker.php index 83b8816..5bdb47b 100644 --- a/src/SchemaFaker/ObjectFaker.php +++ b/src/SchemaFaker/ObjectFaker.php @@ -14,14 +14,10 @@ use function count; use function in_array; -/** - * @internal - */ +/** @internal */ final class ObjectFaker { - /** - * @return array - */ + /** @return array */ public static function generate(Schema $schema, Options $options, bool $request = false): array { $result = []; diff --git a/src/SchemaFaker/SchemaFaker.php b/src/SchemaFaker/SchemaFaker.php index 03f1e99..671c36d 100644 --- a/src/SchemaFaker/SchemaFaker.php +++ b/src/SchemaFaker/SchemaFaker.php @@ -16,26 +16,18 @@ use function Safe\json_decode; use function Safe\json_encode; -/** - * @internal - */ +/** @internal */ final class SchemaFaker { private Schema $schema; - private Options $options; - private bool $request; - public function __construct(Schema $schema, Options $options, bool $request = false) + public function __construct(Schema $schema, private Options $options, private bool $request = false) { - $schemaData = json_decode(json_encode($schema->getSerializableData()), true); - $this->schema = new Schema($this->resolveOfConstraints($schemaData)); - $this->options = $options; - $this->request = $request; + $schemaData = json_decode(json_encode($schema->getSerializableData()), true); + $this->schema = new Schema($this->resolveOfConstraints($schemaData)); } - /** - * @return array|string|bool|int|float - */ + /** @return array|string|bool|int|float */ public function generate(): array|string|bool|int|float { if ($this->schema->type === 'array') { diff --git a/src/SchemaFaker/StringFaker.php b/src/SchemaFaker/StringFaker.php index 5c4be6d..c07e3f7 100644 --- a/src/SchemaFaker/StringFaker.php +++ b/src/SchemaFaker/StringFaker.php @@ -18,9 +18,7 @@ use const DATE_RFC3339; -/** - * @internal - */ +/** @internal */ final class StringFaker { public static function generate(Schema $schema): string diff --git a/tests/Integration/E2ETest.php b/tests/Integration/E2ETest.php index ac9f571..810f286 100644 --- a/tests/Integration/E2ETest.php +++ b/tests/Integration/E2ETest.php @@ -16,9 +16,7 @@ use function Safe\file_get_contents; use function Safe\sprintf; -/** - * @group Integration - */ +/** @group Integration */ class E2ETest extends TestCase { /** @@ -138,9 +136,7 @@ function it_can_generate_valid_component(string $filename) self::assertTrue(true); } - /** - * @return string[][] - */ + /** @return string[][] */ public function specProvider(): array { return [ diff --git a/tests/Integration/OpenAPIFakerTest.php b/tests/Integration/OpenAPIFakerTest.php index 8d81a5a..9cb6c5b 100644 --- a/tests/Integration/OpenAPIFakerTest.php +++ b/tests/Integration/OpenAPIFakerTest.php @@ -344,7 +344,7 @@ function it_can_mock_a_specific_schema() function it_will_mock_the_response() { $yamlSpec = - <<mockResponse('/todos', 'GET'); @@ -451,7 +451,7 @@ function it_will_throw_exception_if_schema_does_not_exist() */ function it_can_set_options() { - $specYaml = <<options); $this->assertMatchesJsonSnapshot($fakeData); @@ -55,7 +55,7 @@ function it_can_generate_items() function it_can_handle_min_items() { $fakeData = ArrayFaker::generate(SchemaFactory::fromJson( - <<< JSON + <<<'JSON' { "type": "array", "items": { @@ -63,7 +63,7 @@ function it_can_handle_min_items() }, "minItems": 3 } -JSON +JSON, ), $this->options); $this->assertMatchesJsonSnapshot($fakeData); @@ -73,7 +73,7 @@ function it_can_handle_min_items() function it_can_handle_max_items() { $fakeData = ArrayFaker::generate(SchemaFactory::fromJson( - <<< JSON + <<<'JSON' { "type": "array", "items": { @@ -81,7 +81,7 @@ function it_can_handle_max_items() }, "maxItems": 10 } -JSON +JSON, ), $this->options); $this->assertMatchesJsonSnapshot($fakeData); @@ -91,7 +91,7 @@ function it_can_handle_max_items() function it_can_handle_both_min_and_max_items() { $fakeData = ArrayFaker::generate(SchemaFactory::fromJson( - <<< JSON + <<<'JSON' { "type": "array", "items": { @@ -100,7 +100,7 @@ function it_can_handle_both_min_and_max_items() "minItems": 8, "maxItems": 10 } -JSON +JSON, ), $this->options); $this->assertMatchesJsonSnapshot($fakeData); @@ -110,14 +110,14 @@ function it_can_handle_both_min_and_max_items() function it_will_use_minimum_plus_15_as_max_items_if_its_not_given() { $fakeData = ArrayFaker::generate(SchemaFactory::fromJson( - <<< JSON + <<<'JSON' { "type": "array", "items": { "type": "string" } } -JSON +JSON, ), $this->options); $this->assertMatchesJsonSnapshot($fakeData); @@ -126,7 +126,7 @@ function it_will_use_minimum_plus_15_as_max_items_if_its_not_given() /** @test */ function it_handles_nested_arrays() { - $yaml = <<options); self::assertIsArray($fakeData); @@ -169,7 +169,7 @@ function it_can_generate_unique_elements() function it_can_generate_elements_from_enum() { $fakeData = ArrayFaker::generate(SchemaFactory::fromYaml( - <<options); $this->assertMatchesJsonSnapshot($fakeData); @@ -194,12 +194,12 @@ function it_can_override_minimum_items_with_option() $options = (new Options())->setMinItems(5); $fakeData = ArrayFaker::generate(SchemaFactory::fromYaml( - <<setMinItems(1); $fakeData = ArrayFaker::generate(SchemaFactory::fromYaml( - <<setMaxItems(3); $fakeData = ArrayFaker::generate(SchemaFactory::fromYaml( - <<setMaxItems(5); $fakeData = ArrayFaker::generate(SchemaFactory::fromYaml( - <<setMinItems(3)->setMaxItems(3); $fakeData = ArrayFaker::generate(SchemaFactory::fromYaml( - <<setMaxItems(4); $fakeData = ArrayFaker::generate(SchemaFactory::fromYaml( - <<setAlwaysFakeOptionals(true); - $yaml = <<