Skip to content

Commit

Permalink
PHP CS Fixer support for PHP ^8.0 (#57)
Browse files Browse the repository at this point in the history
* 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 8f41436.

* Revert "Update composer.json"

This reverts commit 80565be.

* Revert "Update composer.json"

This reverts commit d794a82.

* Update tests.yml
  • Loading branch information
matthew-inamdar committed Jul 20, 2022
1 parent 2b18a2b commit 072f8d9
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 137 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -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

Expand Down
23 changes: 23 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->in(__DIR__)
->exclude([
'media',
'tests',
'vendor',
]);

$rules = [
'@PSR1' => true,
'@PSR2' => true,
];

return (new Config())
->setRules($rules)
->setFinder($finder);
130 changes: 0 additions & 130 deletions .php_cs

This file was deleted.

4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
}
}
8 changes: 4 additions & 4 deletions src/Objects/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
35 changes: 35 additions & 0 deletions tests/Objects/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 072f8d9

Please sign in to comment.