Skip to content

Commit

Permalink
feat: upgrade to doctrine/codingstandard:10 (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
canvural authored Aug 26, 2022
1 parent eed34c1 commit b82d082
Show file tree
Hide file tree
Showing 18 changed files with 101 additions and 139 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/NoResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
18 changes: 6 additions & 12 deletions src/OpenAPIFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
8 changes: 2 additions & 6 deletions src/SchemaFaker/ArrayFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@
use const SORT_REGULAR;
use const SORT_STRING;

/**
* @internal
*/
/** @internal */
final class ArrayFaker
{
/**
* @return array<mixed>
*/
/** @return array<mixed> */
public static function generate(Schema $schema, Options $options): array
{
$minimum = $schema->minItems ?? 0;
Expand Down
4 changes: 1 addition & 3 deletions src/SchemaFaker/BooleanFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

use function random_int;

/**
* @internal
*/
/** @internal */
final class BooleanFaker
{
public static function generate(Schema $schema): bool
Expand Down
4 changes: 1 addition & 3 deletions src/SchemaFaker/NumberFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

use function mt_getrandmax;

/**
* @internal
*/
/** @internal */
final class NumberFaker
{
public static function generate(Schema $schema): int|float
Expand Down
8 changes: 2 additions & 6 deletions src/SchemaFaker/ObjectFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@
use function count;
use function in_array;

/**
* @internal
*/
/** @internal */
final class ObjectFaker
{
/**
* @return array<mixed>
*/
/** @return array<mixed> */
public static function generate(Schema $schema, Options $options, bool $request = false): array
{
$result = [];
Expand Down
18 changes: 5 additions & 13 deletions src/SchemaFaker/SchemaFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<mixed>|string|bool|int|float
*/
/** @return array<mixed>|string|bool|int|float */
public function generate(): array|string|bool|int|float
{
if ($this->schema->type === 'array') {
Expand Down
4 changes: 1 addition & 3 deletions src/SchemaFaker/StringFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

use const DATE_RFC3339;

/**
* @internal
*/
/** @internal */
final class StringFaker
{
public static function generate(Schema $schema): string
Expand Down
8 changes: 2 additions & 6 deletions tests/Integration/E2ETest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
use function Safe\file_get_contents;
use function Safe\sprintf;

/**
* @group Integration
*/
/** @group Integration */
class E2ETest extends TestCase
{
/**
Expand Down Expand Up @@ -138,9 +136,7 @@ function it_can_generate_valid_component(string $filename)
self::assertTrue(true);
}

/**
* @return string[][]
*/
/** @return string[][] */
public function specProvider(): array
{
return [
Expand Down
8 changes: 4 additions & 4 deletions tests/Integration/OpenAPIFakerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ function it_can_mock_a_specific_schema()
function it_will_mock_the_response()
{
$yamlSpec =
<<<YAML
<<<'YAML'
openapi: 3.0.2
paths:
/todos:
Expand All @@ -355,7 +355,7 @@ function it_will_mock_the_response()
content:
'application/json':
schema:
\$ref: "#/components/schemas/Todos"
$ref: "#/components/schemas/Todos"
components:
schemas:
Todo:
Expand All @@ -374,7 +374,7 @@ function it_will_mock_the_response()
Todos:
type: array
items:
\$ref: "#/components/schemas/Todo"
$ref: "#/components/schemas/Todo"
YAML;

$fakeData = OpenAPIFaker::createFromYaml($yamlSpec)->mockResponse('/todos', 'GET');
Expand Down Expand Up @@ -451,7 +451,7 @@ function it_will_throw_exception_if_schema_does_not_exist()
*/
function it_can_set_options()
{
$specYaml = <<<YAML
$specYaml = <<<'YAML'
openapi: 3.0.2
components:
schemas:
Expand Down
Loading

0 comments on commit b82d082

Please sign in to comment.