Skip to content

Commit

Permalink
cs fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
vsouz4 committed Dec 13, 2023
1 parent 4708082 commit 3d41a14
Show file tree
Hide file tree
Showing 112 changed files with 740 additions and 624 deletions.
12 changes: 2 additions & 10 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

use PhpCsFixer\Config;

$header = <<<'EOT'
This file was generated by docler-labs/api-client-generator.
Do not edit it manually.
EOT;

$rules = [
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
Expand All @@ -16,7 +10,7 @@
'echo_tag_syntax' => ['format' => 'long'],
'no_unused_imports' => true,
'blank_line_after_opening_tag' => true,
'not_operator_with_successor_space' => true,
'not_operator_with_successor_space' => false,
'no_useless_else' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'class_attributes_separation' => [
Expand Down Expand Up @@ -50,14 +44,12 @@
'no_leading_import_slash' => true,
'declare_strict_types' => true,
'single_line_after_imports' => true,
'header_comment' => ['header' => $header],
'not_operator_with_space' => false,
'no_spaces_inside_parenthesis' => true,
'unary_operator_spaces' => true,
'return_type_declaration' => ['space_before' => 'none'],
'native_function_invocation' => ['include' => ['@all']],
'braces' => ['allow_single_line_closure' => true],
'binary_operator_spaces' => ['default' => 'align_single_space_minimal'],
'binary_operator_spaces' => ['operators' => ['=>' => 'align_single_space_minimal', '=' => 'align_single_space_minimal']],
'no_superfluous_phpdoc_tags' => true,
'no_empty_phpdoc' => true,
'no_extra_blank_lines' => true,
Expand Down
69 changes: 69 additions & 0 deletions .php-cs-fixer.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

use PhpCsFixer\Config;

$header = <<<'EOT'
This file was generated by docler-labs/api-client-generator.

Do not edit it manually.
EOT;

$rules = [
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
'no_blank_lines_after_class_opening' => true,
'echo_tag_syntax' => ['format' => 'long'],
'no_unused_imports' => true,
'blank_line_after_opening_tag' => true,
'not_operator_with_successor_space' => false,
'no_useless_else' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'class_attributes_separation' => [
'elements' => [
'const' => 'one',
'method' => 'one',
'property' => 'one',
],
],
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'return', 'try'],
],
'no_alternative_syntax' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_align' => ['align' => 'vertical'],
'phpdoc_indent' => true,
'phpdoc_no_package' => true,
'phpdoc_order' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_trim' => true,
'phpdoc_var_without_name' => true,
'phpdoc_to_comment' => true,
'phpdoc_scalar' => [
'types' => ['boolean', 'double', 'integer', 'real', 'str'],
],
'single_quote' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'trim_array_spaces' => true,
'no_leading_import_slash' => true,
'declare_strict_types' => true,
'single_line_after_imports' => true,
'header_comment' => ['header' => $header],
'not_operator_with_space' => false,
'no_spaces_inside_parenthesis' => true,
'unary_operator_spaces' => true,
'return_type_declaration' => ['space_before' => 'none'],
'braces' => ['allow_single_line_closure' => true],
'binary_operator_spaces' => ['operators' => ['=>' => 'align_single_space_minimal', '=' => 'align_single_space_minimal']],
'no_superfluous_phpdoc_tags' => true,
'no_empty_phpdoc' => true,
'no_extra_blank_lines' => true,
];

return (new Config())
->setRiskyAllowed(true)
->setRules($rules)
->setIndent(' ')
->setUsingCache(false);
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The following environment variables are available:
| `PACKAGE` | yes | | | group/some-api-client |
| `OPENAPI ` | yes | | | /api/openapi.yaml |
| `OUTPUT_DIR` | yes | | | /client |
| `CODE_STYLE` | no | {path-to-repository}/.php-cs-fixer.php | | /client/myCodeStyle.php |
| `CODE_STYLE` | no | {path-to-repository}/.php-cs-fixer.php.dist | | /client/myCodeStyle.php |
| `SOURCE_DIR` | no | src | | src |
| `CLIENT_PHP_VERSION` | no | 7.4 | 7.0, 7.1, 7.2, 7.3, 7.4, 8.0 | 7.4 |
| `COMPOSER_JSON_TEMPLATE_DIR` | no | {path-to-repository}/template/composer.json.twig | | /path/composer.json.twig |
Expand Down
2 changes: 2 additions & 0 deletions example/PetStoreApiConsumer/PetStoreApiConsumer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace OpenApi\PetStoreApiConsumer;

use GuzzleHttp\Client;
Expand Down
6 changes: 3 additions & 3 deletions example/PetStoreClient/src/Request/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class CookieJar
public function __construct(array $cookies = [])
{
foreach ($cookies as $name => $value) {
if (\preg_match('/[\\x00-\\x20\\x22\\x28-\\x29\\x2c\\x2f\\x3a-\\x40\\x5c\\x7b\\x7d\\x7f]/', $name)) {
if (preg_match('/[\\x00-\\x20\\x22\\x28-\\x29\\x2c\\x2f\\x3a-\\x40\\x5c\\x7b\\x7d\\x7f]/', $name)) {
throw new InvalidArgumentException('Cookie name must not contain invalid characters: ASCII ' . 'Control characters (0-31;127), space, tab and the following characters: ()<>@,;:\\"/?={}');
}
// Value must not be empty, but can be 0
if (empty($value) && ! \is_numeric($value)) {
if (empty($value) && !is_numeric($value)) {
throw new InvalidArgumentException('The cookie value must not be empty');
}
}
Expand All @@ -34,6 +34,6 @@ public function __construct(array $cookies = [])

public function withCookieHeader(RequestInterface $request): RequestInterface
{
return empty($this->cookies) ? $request : $request->withHeader('Cookie', \http_build_query($this->cookies, '', '; '));
return empty($this->cookies) ? $request : $request->withHeader('Cookie', http_build_query($this->cookies, '', '; '));
}
}
2 changes: 1 addition & 1 deletion example/PetStoreClient/src/Request/DeleteOrderRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getMethod(): string

public function getRoute(): string
{
return \strtr('store/order/{orderId}', ['{orderId}' => $this->orderId]);
return strtr('store/order/{orderId}', ['{orderId}' => $this->orderId]);
}

public function getQueryParameters(): array
Expand Down
6 changes: 3 additions & 3 deletions example/PetStoreClient/src/Request/DeletePetRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getMethod(): string

public function getRoute(): string
{
return \strtr('pet/{petId}', ['{petId}' => $this->petId]);
return strtr('pet/{petId}', ['{petId}' => $this->petId]);
}

public function getQueryParameters(): array
Expand All @@ -64,9 +64,9 @@ public function getCookies(): array

public function getHeaders(): array
{
return \array_merge([], \array_map(static function ($value) {
return array_merge([], array_map(static function ($value) {
return $value instanceof SerializableInterface ? $value->toArray() : $value;
}, \array_filter(['api_key' => $this->apiKey], static function ($value) {
}, array_filter(['api_key' => $this->apiKey], static function ($value) {
return null !== $value;
})));
}
Expand Down
2 changes: 1 addition & 1 deletion example/PetStoreClient/src/Request/DeleteUserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getMethod(): string

public function getRoute(): string
{
return \strtr('user/{username}', ['{username}' => $this->username]);
return strtr('user/{username}', ['{username}' => $this->username]);
}

public function getQueryParameters(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public function getRoute(): string

public function getQueryParameters(): array
{
return \array_map(static function ($value) {
return array_map(static function ($value) {
return $value instanceof SerializableInterface ? $value->toArray() : $value;
}, \array_filter(['status' => $this->status], static function ($value) {
}, array_filter(['status' => $this->status], static function ($value) {
return null !== $value;
}));
}
Expand Down
4 changes: 2 additions & 2 deletions example/PetStoreClient/src/Request/FindPetsByTagsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public function getRoute(): string

public function getQueryParameters(): array
{
return \array_map(static function ($value) {
return array_map(static function ($value) {
return $value instanceof SerializableInterface ? $value->toArray() : $value;
}, \array_filter(['tags' => $this->tags], static function ($value) {
}, array_filter(['tags' => $this->tags], static function ($value) {
return null !== $value;
}));
}
Expand Down
2 changes: 1 addition & 1 deletion example/PetStoreClient/src/Request/GetOrderByIdRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getMethod(): string

public function getRoute(): string
{
return \strtr('store/order/{orderId}', ['{orderId}' => $this->orderId]);
return strtr('store/order/{orderId}', ['{orderId}' => $this->orderId]);
}

public function getQueryParameters(): array
Expand Down
2 changes: 1 addition & 1 deletion example/PetStoreClient/src/Request/GetPetByIdRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getMethod(): string

public function getRoute(): string
{
return \strtr('pet/{petId}', ['{petId}' => $this->petId]);
return strtr('pet/{petId}', ['{petId}' => $this->petId]);
}

public function getQueryParameters(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getMethod(): string

public function getRoute(): string
{
return \strtr('user/{username}', ['{username}' => $this->username]);
return strtr('user/{username}', ['{username}' => $this->username]);
}

public function getQueryParameters(): array
Expand Down
4 changes: 2 additions & 2 deletions example/PetStoreClient/src/Request/LoginUserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public function getRoute(): string

public function getQueryParameters(): array
{
return \array_map(static function ($value) {
return array_map(static function ($value) {
return $value instanceof SerializableInterface ? $value->toArray() : $value;
}, \array_filter(['username' => $this->username, 'password' => $this->password], static function ($value) {
}, array_filter(['username' => $this->username, 'password' => $this->password], static function ($value) {
return null !== $value;
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ public function getMethod(): string

public function getRoute(): string
{
return \strtr('pet/{petId}', ['{petId}' => $this->petId]);
return strtr('pet/{petId}', ['{petId}' => $this->petId]);
}

public function getQueryParameters(): array
{
return \array_map(static function ($value) {
return array_map(static function ($value) {
return $value instanceof SerializableInterface ? $value->toArray() : $value;
}, \array_filter(['name' => $this->name, 'status' => $this->status], static function ($value) {
}, array_filter(['name' => $this->name, 'status' => $this->status], static function ($value) {
return null !== $value;
}));
}
Expand Down
2 changes: 1 addition & 1 deletion example/PetStoreClient/src/Request/UpdateUserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getMethod(): string

public function getRoute(): string
{
return \strtr('user/{username}', ['{username}' => $this->username]);
return strtr('user/{username}', ['{username}' => $this->username]);
}

public function getQueryParameters(): array
Expand Down
2 changes: 1 addition & 1 deletion example/PetStoreClient/src/Response/ResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public function handle(ResponseInterface $response): array
if ($statusCode >= 200 && $statusCode < 300) {
return $this->bodySerializer->unserializeResponse($response);
}
throw $this->responseExceptionFactory->create(\sprintf('Server replied with a non-200 status code: %s', $response->getStatusCode()), $response);
throw $this->responseExceptionFactory->create(sprintf('Server replied with a non-200 status code: %s', $response->getStatusCode()), $response);
}
}
6 changes: 3 additions & 3 deletions example/PetStoreClient/src/Schema/Mapper/PetMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function __construct(CategoryMapper $categoryMapper, TagCollectionMapper
*/
public function toSchema(array $payload): Pet
{
$missingFields = \implode(', ', \array_diff(['name', 'photoUrls'], \array_keys($payload)));
if (! empty($missingFields)) {
$missingFields = implode(', ', array_diff(['name', 'photoUrls'], array_keys($payload)));
if (!empty($missingFields)) {
throw new UnexpectedResponseBodyException('Required attributes for `Pet` missing in the response body: ' . $missingFields);
}
$schema = new Pet($payload['name'], $payload['photoUrls']);
Expand All @@ -47,7 +47,7 @@ public function toSchema(array $payload): Pet
if (isset($payload['status'])) {
$schema->setStatus($payload['status']);
}
if (\array_key_exists('chipped', $payload)) {
if (array_key_exists('chipped', $payload)) {
$schema->setChipped($payload['chipped']);
}

Expand Down
4 changes: 2 additions & 2 deletions example/PetStoreClient/src/Schema/PetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public function getIterator(): ArrayIterator

public function count(): int
{
return \count($this->items);
return count($this->items);
}

public function first(): ?Pet
{
$first = \reset($this->items);
$first = reset($this->items);
if ($first === false) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions example/PetStoreClient/src/Schema/TagCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public function getIterator(): ArrayIterator

public function count(): int
{
return \count($this->items);
return count($this->items);
}

public function first(): ?Tag
{
$first = \reset($this->items);
$first = reset($this->items);
if ($first === false) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions example/PetStoreClient/src/Schema/UserCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public function getIterator(): ArrayIterator

public function count(): int
{
return \count($this->items);
return count($this->items);
}

public function first(): ?User
{
$first = \reset($this->items);
$first = reset($this->items);
if ($first === false) {
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions example/PetStoreClient/src/Serializer/BodySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public function unserializeResponse(ResponseInterface $response): array

private function getContentTypeSerializer(string $contentType): ContentTypeSerializerInterface
{
$contentType = \strtolower(\trim(\explode(';', $contentType)[0]));
if (! isset($this->contentTypeSerializers[$contentType])) {
throw new InvalidArgumentException(\sprintf('Serializer for `%s` is not found. Supported: %s', $contentType, \json_encode(\array_keys($this->contentTypeSerializers))));
$contentType = strtolower(trim(explode(';', $contentType)[0]));
if (!isset($this->contentTypeSerializers[$contentType])) {
throw new InvalidArgumentException(sprintf('Serializer for `%s` is not found. Supported: %s', $contentType, json_encode(array_keys($this->contentTypeSerializers))));
}

return $this->contentTypeSerializers[$contentType];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ abstract class AbstractJsonContentTypeSerializer implements ContentTypeSerialize
*/
public function encode(SerializableInterface $body): string
{
$encodedData = \json_encode($body->toArray(), self::JSON_OPTIONS);
$lastErrorCode = \json_last_error();
$encodedData = json_encode($body->toArray(), self::JSON_OPTIONS);
$lastErrorCode = json_last_error();
if ($lastErrorCode === JSON_ERROR_NONE && $encodedData !== false) {
return $encodedData;
}
Expand All @@ -40,10 +40,10 @@ public function decode(StreamInterface $body): array
$body->rewind();
// According to RFC7159 a JSON value MUST be an object, array, number, string,
// or one of the following three literal names: false, null, true.
$result = \json_decode($body->getContents(), true, self::JSON_DEPTH, self::JSON_OPTIONS);
$lastErrorCode = \json_last_error();
$result = json_decode($body->getContents(), true, self::JSON_DEPTH, self::JSON_OPTIONS);
$lastErrorCode = json_last_error();
if ($lastErrorCode === JSON_ERROR_NONE) {
if (! \is_array($result)) {
if (!is_array($result)) {
$result = [ContentTypeSerializerInterface::LITERAL_VALUE_KEY => $result];
}

Expand Down
Loading

0 comments on commit 3d41a14

Please sign in to comment.