From 072f8d9f6e75f68df28b148103b38fdf843467b2 Mon Sep 17 00:00:00 2001 From: Matt Inamdar Date: Wed, 20 Jul 2022 10:57:04 +0100 Subject: [PATCH] PHP CS Fixer support for PHP ^8.0 (#57) * Update .php-cs-fixer.php * Update composer.json * Update composer.json * Removed udiff format * Simplified code style * Added schema contract support for properties * Update composer.json * Update composer.json * Update composer.json * Revert "Update composer.json" This reverts commit 8f414368a053a524ad64a040645817527e6574c2. * Revert "Update composer.json" This reverts commit 80565beafaa4d63d2755d7dd7c6d5f01030b9d11. * Revert "Update composer.json" This reverts commit d794a8200a534df8e8298059ee5a86a1a788e549. * Update tests.yml --- .github/workflows/tests.yml | 3 + .gitignore | 3 +- .php-cs-fixer.php | 23 +++++++ .php_cs | 130 ----------------------------------- composer.json | 4 +- src/Objects/Schema.php | 8 +-- tests/Objects/SchemaTest.php | 35 ++++++++++ 7 files changed, 69 insertions(+), 137 deletions(-) create mode 100644 .php-cs-fixer.php delete mode 100644 .php_cs diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ce2514f..74d8855 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,6 +32,9 @@ jobs: - name: Install dependencies run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress + - name: Install dev dependencies + run: composer update --dev --prefer-stable --prefer-dist --no-interaction --no-progress + - name: Run PHP CS Fixer run: composer test:style diff --git a/.gitignore b/.gitignore index 506f06b..fe9e6dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /composer.lock -/.php_cs.cache +/.php-cs-fixer.cache +/.phpunit.result.cache # Created by https://www.gitignore.io/api/macos,phpstorm,composer diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..6d52409 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,23 @@ +in(__DIR__) + ->exclude([ + 'media', + 'tests', + 'vendor', + ]); + +$rules = [ + '@PSR1' => true, + '@PSR2' => true, +]; + +return (new Config()) + ->setRules($rules) + ->setFinder($finder); diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 444143f..0000000 --- a/.php_cs +++ /dev/null @@ -1,130 +0,0 @@ -in(__DIR__) - ->exclude([ - 'media', - 'tests', - 'vendor', - ]); - -$rules = [ - '@PSR1' => true, - '@PSR2' => true, - - 'align_multiline_comment' => true, - 'array_indentation' => true, - 'array_syntax' => [ - 'syntax' => 'short', - ], - 'blank_line_after_opening_tag' => true, - 'blank_line_before_statement' => [ - 'statements' => ['return', 'throw'], - ], - 'cast_spaces' => [ - 'space' => 'none', - ], - 'class_attributes_separation' => [ - 'elements' => ['method', 'property'], - ], - 'combine_consecutive_issets' => true, - 'combine_consecutive_unsets' => true, - 'compact_nullable_typehint' => true, - 'concat_space' => [ - 'spacing' => 'one', - ], - 'declare_equal_normalize' => true, - 'declare_strict_types' => true, - 'ereg_to_preg' => true, - 'fully_qualified_strict_types' => true, - 'function_to_constant' => true, - 'function_typehint_space' => true, - 'heredoc_indentation' => true, - 'heredoc_to_nowdoc' => true, - 'list_syntax' => true, - 'logical_operators' => true, - 'lowercase_cast' => true, - 'lowercase_static_reference' => true, - 'magic_constant_casing' => true, - 'magic_method_casing' => true, - 'mb_str_functions' => true, - 'method_chaining_indentation' => true, - 'modernize_types_casting' => true, - 'multiline_comment_opening_closing' => true, - 'multiline_whitespace_before_semicolons' => true, - 'native_function_casing' => true, - 'native_function_type_declaration_casing' => true, - 'new_with_braces' => true, - 'no_alias_functions' => true, - 'no_alternative_syntax' => true, - 'no_blank_lines_after_class_opening' => true, - 'no_blank_lines_after_phpdoc' => true, - 'no_break_comment' => [ - 'comment_text' => 'No break.', - ], - 'no_empty_phpdoc' => true, - 'no_empty_statement' => true, - 'no_extra_blank_lines' => true, - 'no_leading_import_slash' => true, - 'no_leading_namespace_whitespace' => true, - 'no_mixed_echo_print' => true, - 'no_multiline_whitespace_around_double_arrow' => true, - 'no_php4_constructor' => true, - 'no_short_bool_cast' => true, - 'no_short_echo_tag' => true, - 'no_singleline_whitespace_before_semicolons' => true, - 'no_spaces_around_offset' => true, - 'no_unused_imports' => true, - 'no_whitespace_before_comma_in_array' => true, - 'no_whitespace_in_blank_line' => true, - 'normalize_index_brace' => true, - 'object_operator_without_whitespace' => true, - 'ordered_imports' => true, - 'phpdoc_add_missing_param_annotation' => true, - 'phpdoc_align' => [ - 'align' => 'left', - ], - 'phpdoc_annotation_without_dot' => true, - 'phpdoc_indent' => true, - 'phpdoc_no_empty_return' => true, - 'phpdoc_no_package' => true, - 'phpdoc_order' => true, - 'phpdoc_scalar' => true, - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_summary' => true, - 'phpdoc_trim' => true, - 'phpdoc_trim_consecutive_blank_line_separation' => true, - 'phpdoc_types' => true, - 'phpdoc_types_order' => [ - 'null_adjustment' => 'always_last', - 'sort_algorithm' => 'none', - ], - 'phpdoc_var_annotation_correct_order' => true, - 'phpdoc_var_without_name' => true, - 'random_api_migration' => true, - 'return_type_declaration' => true, - 'semicolon_after_instruction' => true, - 'set_type_to_cast' => true, - 'short_scalar_cast' => true, - 'simple_to_complex_string_variable' => true, - 'simplified_null_return' => true, - 'single_blank_line_before_namespace' => true, - 'single_line_comment_style' => true, - 'single_quote' => true, - 'single_trait_insert_per_statement' => true, - 'standardize_not_equals' => true, - 'ternary_operator_spaces' => true, - 'ternary_to_null_coalescing' => true, - 'trailing_comma_in_multiline_array' => true, - 'trim_array_spaces' => true, - 'unary_operator_spaces' => true, -]; - -return Config::create() - ->setRules($rules) - ->setFinder($finder); diff --git a/composer.json b/composer.json index 281025d..72f21e0 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "require-dev": { "phpunit/phpunit": ">=7.3", - "friendsofphp/php-cs-fixer": "^2.17", + "friendsofphp/php-cs-fixer": "^3", "justinrainbow/json-schema": "^5.2" }, "suggest": { @@ -44,6 +44,6 @@ ], "test:style": "@fix:style --dry-run", "test:unit": "@php vendor/bin/phpunit", - "fix:style": "@php vendor/bin/php-cs-fixer fix --config=.php_cs --allow-risky=yes --diff --diff-format=udiff --verbose" + "fix:style": "@php vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --allow-risky=yes --diff --verbose" } } diff --git a/src/Objects/Schema.php b/src/Objects/Schema.php index 0bc534e..0fd89da 100644 --- a/src/Objects/Schema.php +++ b/src/Objects/Schema.php @@ -28,7 +28,7 @@ * @property int|float|null $exclusiveMinimum * @property int|float|null $multipleOf * @property string[]|null $required - * @property \GoldSpecDigital\ObjectOrientedOAS\Objects\Schema[]|null $properties + * @property \GoldSpecDigital\ObjectOrientedOAS\Contracts\SchemaContract[]|null $properties * @property \GoldSpecDigital\ObjectOrientedOAS\Objects\Schema|null $additionalProperties * @property int|null $maxProperties * @property int|null $minProperties @@ -157,7 +157,7 @@ class Schema extends BaseObject implements SchemaContract protected $required; /** - * @var \GoldSpecDigital\ObjectOrientedOAS\Objects\Schema[]|null + * @var \GoldSpecDigital\ObjectOrientedOAS\Contracts\SchemaContract[]|null */ protected $properties; @@ -584,10 +584,10 @@ public function required(...$required): self } /** - * @param \GoldSpecDigital\ObjectOrientedOAS\Objects\Schema[] $properties + * @param \GoldSpecDigital\ObjectOrientedOAS\Contracts\SchemaContract[] $properties * @return static */ - public function properties(Schema ...$properties): self + public function properties(SchemaContract ...$properties): self { $instance = clone $this; diff --git a/tests/Objects/SchemaTest.php b/tests/Objects/SchemaTest.php index 05125fb..9662381 100644 --- a/tests/Objects/SchemaTest.php +++ b/tests/Objects/SchemaTest.php @@ -7,6 +7,7 @@ use GoldSpecDigital\ObjectOrientedOAS\Objects\Discriminator; use GoldSpecDigital\ObjectOrientedOAS\Objects\ExternalDocs; use GoldSpecDigital\ObjectOrientedOAS\Objects\MediaType; +use GoldSpecDigital\ObjectOrientedOAS\Objects\OneOf; use GoldSpecDigital\ObjectOrientedOAS\Objects\Schema; use GoldSpecDigital\ObjectOrientedOAS\Objects\Xml; use GoldSpecDigital\ObjectOrientedOAS\Tests\TestCase; @@ -320,4 +321,38 @@ public function create_array_with_ref_works() ], ], $schema->toArray()); } + + /** @test */ + public function create_object_with_oneOf_works() + { + $string = Schema::string(); + $number = Schema::number(); + + $schema = Schema::create() + ->type(Schema::TYPE_OBJECT) + ->properties( + OneOf::create('poly_type')->schemas($string, $number) + ); + + $response = MediaType::create() + ->schema($schema); + + $this->assertEquals([ + 'schema' => [ + 'type' => 'object', + 'properties' => [ + 'poly_type' => [ + 'oneOf' => [ + [ + 'type' => 'string', + ], + [ + 'type' => 'number', + ], + ], + ], + ], + ], + ], $response->toArray()); + } }