From 8e4556a8a817f203e591d64b3db9a953d42009f1 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Tue, 21 Apr 2020 14:03:17 +0200 Subject: [PATCH] Fix styling --- .github/workflows/test.yml | 2 +- composer.lock | 51 ++++++++----------- src/PHPDraft/Core/Autoloader.php | 1 + src/PHPDraft/In/ApibFileParser.php | 3 +- src/PHPDraft/In/Tests/ApibFileParserTest.php | 6 +-- src/PHPDraft/Model/Category.php | 1 + src/PHPDraft/Model/Comparable.php | 1 + .../Model/Elements/ArrayStructureElement.php | 3 +- .../Model/Elements/BasicStructureElement.php | 11 ++-- .../Model/Elements/EnumStructureElement.php | 5 +- .../Model/Elements/ObjectStructureElement.php | 16 ++++-- .../Model/Elements/RequestBodyElement.php | 1 + .../Model/Elements/StructureElement.php | 3 +- .../Tests/ArrayStructureElementTest.php | 16 +++--- .../Tests/BasicStructureElementTest.php | 2 +- .../Tests/EnumStructureElementTest.php | 10 ++-- src/PHPDraft/Model/HTTPRequest.php | 1 + src/PHPDraft/Model/HTTPResponse.php | 1 + src/PHPDraft/Model/HierarchyElement.php | 1 + src/PHPDraft/Model/Resource.php | 1 + src/PHPDraft/Model/Transition.php | 5 +- src/PHPDraft/Out/BaseTemplateGenerator.php | 1 + src/PHPDraft/Out/Sorting.php | 1 + src/PHPDraft/Out/TemplateGenerator.php | 1 + src/PHPDraft/Out/Version.php | 1 + src/PHPDraft/Parse/BaseHtmlGenerator.php | 1 + src/PHPDraft/Parse/BaseParser.php | 1 + src/PHPDraft/Parse/Drafter.php | 1 + src/PHPDraft/Parse/DrafterAPI.php | 1 + src/PHPDraft/Parse/ExecutionException.php | 1 + src/PHPDraft/Parse/HtmlGenerator.php | 1 + src/PHPDraft/Parse/LegacyDrafter.php | 1 + src/PHPDraft/Parse/ParserFactory.php | 1 + src/PHPDraft/Parse/ResourceException.php | 1 + tests/phpcs.xml | 9 ++++ tests/statics/drafter/html/basic.html | 11 ++-- tests/statics/drafter/html/material.html | 7 ++- 37 files changed, 104 insertions(+), 77 deletions(-) create mode 100644 tests/phpcs.xml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0409bd40..0b1a6156 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,7 +54,7 @@ jobs: run: phpstan analyse --level=4 --error-format=checkstyle src/ | cs2pr - name: PHPCS - run: phpcs --standard=PSR12 --ignore=\*/Tests/\*,\*Minifier.php --exclude=PSR1.Methods.CamelCapsMethodName,Generic.Files.LineLength src/ | cs2pr + run: phpcs --standard=tests/phpcs.xml --ignore=\*Minifier.php src/ | cs2pr - name: Upload coverage result uses: actions/upload-artifact@v1 diff --git a/composer.lock b/composer.lock index b990d47b..f89c151f 100644 --- a/composer.lock +++ b/composer.lock @@ -809,21 +809,24 @@ }, { "name": "phpstan/phpstan", - "version": "0.12.18", + "version": "0.12.19", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "1ce27fe29c8660a27926127d350d53d80c4d4286" + "reference": "054f6d76b12ba9a6c13a5a8d5fcdf51219615f4d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/1ce27fe29c8660a27926127d350d53d80c4d4286", - "reference": "1ce27fe29c8660a27926127d350d53d80c4d4286", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/054f6d76b12ba9a6c13a5a8d5fcdf51219615f4d", + "reference": "054f6d76b12ba9a6c13a5a8d5fcdf51219615f4d", "shasum": "" }, "require": { "php": "^7.1" }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, "bin": [ "phpstan", "phpstan.phar" @@ -844,39 +847,25 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", - "funding": [ - { - "url": "https://github.com/ondrejmirtes", - "type": "github" - }, - { - "url": "https://www.patreon.com/phpstan", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", - "type": "tidelift" - } - ], - "time": "2020-03-22T16:51:47+00:00" + "time": "2020-04-19T20:35:10+00:00" }, { "name": "phpstan/phpstan-phpunit", - "version": "0.12.6", + "version": "0.12.8", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "26394996368b6d033d012547d3197f4e07e23021" + "reference": "7232c17e2493dc598173da784477ce0afb2c4e0e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/26394996368b6d033d012547d3197f4e07e23021", - "reference": "26394996368b6d033d012547d3197f4e07e23021", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/7232c17e2493dc598173da784477ce0afb2c4e0e", + "reference": "7232c17e2493dc598173da784477ce0afb2c4e0e", "shasum": "" }, "require": { "php": "~7.1", - "phpstan/phpstan": "^0.12.4" + "phpstan/phpstan": "^0.12.6" }, "conflict": { "phpunit/phpunit": "<7.0" @@ -914,7 +903,7 @@ "MIT" ], "description": "PHPUnit extensions and rules for PHPStan", - "time": "2020-01-10T12:07:21+00:00" + "time": "2020-04-17T08:04:10+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2081,16 +2070,16 @@ }, { "name": "webmozart/assert", - "version": "1.7.0", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "aed98a490f9a8f78468232db345ab9cf606cf598" + "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/aed98a490f9a8f78468232db345ab9cf606cf598", - "reference": "aed98a490f9a8f78468232db345ab9cf606cf598", + "url": "https://api.github.com/repos/webmozart/assert/zipball/ab2cb0b3b559010b75981b1bdce728da3ee90ad6", + "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6", "shasum": "" }, "require": { @@ -2098,7 +2087,7 @@ "symfony/polyfill-ctype": "^1.8" }, "conflict": { - "vimeo/psalm": "<3.6.0" + "vimeo/psalm": "<3.9.1" }, "require-dev": { "phpunit/phpunit": "^4.8.36 || ^7.5.13" @@ -2125,7 +2114,7 @@ "check", "validate" ], - "time": "2020-02-14T12:15:55+00:00" + "time": "2020-04-18T12:12:48+00:00" }, { "name": "zetacomponents/base", diff --git a/src/PHPDraft/Core/Autoloader.php b/src/PHPDraft/Core/Autoloader.php index a983e94b..e21a78e2 100644 --- a/src/PHPDraft/Core/Autoloader.php +++ b/src/PHPDraft/Core/Autoloader.php @@ -1,4 +1,5 @@ setAccessible(true); $text = "FORMAT: 1A\nHOST: https://owner-api.teslamotors.com\n"; - $text .="EXTRA_HOSTS: https://test.owner-api.teslamotors.com\nSOMETHING: INFO\n\n"; + $text .= "EXTRA_HOSTS: https://test.owner-api.teslamotors.com\nSOMETHING: INFO\n\n"; $text .= "# Tesla Model S JSON API\nThis is unofficial documentation of the"; - $text .=" Tesla Model S JSON API used by the iOS and Android apps. It features"; - $text .=" functionality to monitor and control the Model S remotely.\n\nTEST"; + $text .= " Tesla Model S JSON API used by the iOS and Android apps. It features"; + $text .= " functionality to monitor and control the Model S remotely.\n\nTEST"; $text .= "\n\n# Hello\nThis is a test.\nhello"; $this->assertSame($text, $full_property->getValue($this->class)); diff --git a/src/PHPDraft/Model/Category.php b/src/PHPDraft/Model/Category.php index d8206b84..08ec4e52 100644 --- a/src/PHPDraft/Model/Category.php +++ b/src/PHPDraft/Model/Category.php @@ -1,4 +1,5 @@ element ?? 'any'; - $value = $sub_item->content ?? NULL; + $value = $sub_item->content ?? null; $this->value[] = [$value => $key]; } diff --git a/src/PHPDraft/Model/Elements/BasicStructureElement.php b/src/PHPDraft/Model/Elements/BasicStructureElement.php index 073d0e89..38fe325e 100644 --- a/src/PHPDraft/Model/Elements/BasicStructureElement.php +++ b/src/PHPDraft/Model/Elements/BasicStructureElement.php @@ -1,4 +1,5 @@ description = htmlentities($object->meta->description); } if ($this->description !== null) { - $encoded = htmlentities($this->description, ENT_COMPAT, null, FALSE); + $encoded = htmlentities($this->description, ENT_COMPAT, null, false); $this->description = MarkdownExtra::defaultTransform($encoded); } @@ -133,7 +134,7 @@ protected function parse_common(object $object, array &$dependencies): void $this->status = join(', ', $object->attributes->typeAttributes); } - if (!in_array($this->type, self::DEFAULTS) && $this->type !== NULL) { + if (!in_array($this->type, self::DEFAULTS) && $this->type !== null) { $dependencies[] = $this->type; } } @@ -162,18 +163,18 @@ protected function get_element_as_html($element): string * * @return string */ - public function string_value($flat = FALSE) + public function string_value($flat = false) { if (is_array($this->value)) { $value_key = rand(0, count($this->value)); - if (is_subclass_of($this->value[$value_key], StructureElement::class) && $flat === FALSE) { + if (is_subclass_of($this->value[$value_key], StructureElement::class) && $flat === false) { return $this->value[$value_key]->string_value($flat); } return $this->value[$value_key]; } - if (is_subclass_of($this->value, BasicStructureElement::class) && $flat === TRUE) { + if (is_subclass_of($this->value, BasicStructureElement::class) && $flat === true) { return is_array($this->value->value) ? array_keys($this->value->value)[0] : $this->value->value; } return $this->value; diff --git a/src/PHPDraft/Model/Elements/EnumStructureElement.php b/src/PHPDraft/Model/Elements/EnumStructureElement.php index 8625af1a..685cb1da 100644 --- a/src/PHPDraft/Model/Elements/EnumStructureElement.php +++ b/src/PHPDraft/Model/Elements/EnumStructureElement.php @@ -1,4 +1,5 @@ parse_common($object, $dependencies); - $this->key = $this->key ?? $object->content->content ?? NULL; - $this->type = $this->type ?? $object->content->element ?? NULL; + $this->key = $this->key ?? $object->content->content ?? null; + $this->type = $this->type ?? $object->content->element ?? null; if (!isset($object->content) && !isset($object->attributes)) { $this->value = $this->key; diff --git a/src/PHPDraft/Model/Elements/ObjectStructureElement.php b/src/PHPDraft/Model/Elements/ObjectStructureElement.php index 083d5058..7bd61fad 100644 --- a/src/PHPDraft/Model/Elements/ObjectStructureElement.php +++ b/src/PHPDraft/Model/Elements/ObjectStructureElement.php @@ -1,4 +1,5 @@ object = NULL;} + public function __clearForTest() + { + $this->object = null; + } /** * Parse a JSON object to a data structure. @@ -58,7 +62,9 @@ public function parse(?object $object, array &$dependencies): StructureElement $this->value = $object->content->value->content; } elseif (isset($object->content->value->attributes->samples)) { $this->value = array_reduce($object->content->value->attributes->samples->content, function ($carry, $item) { - if ($carry === NULL) {return "$item->content ($item->element)"; } + if ($carry === null) { + return "$item->content ($item->element)"; + } return "$carry | $item->content ($item->element)"; }); } else { @@ -106,7 +112,7 @@ protected function new_instance(): StructureElement * Parse content formed as an array. * * @param object $object APIB content - * @param array $dependencies Object dependencies + * @param array $dependencies Object dependencies * * @return void */ @@ -130,7 +136,7 @@ protected function parse_array_content(object $object, array &$dependencies): vo */ public function __toString(): string { - $options = array_merge(self::DEFAULTS,['member', 'select', 'option', 'ref', 'T', 'hrefVariables']); + $options = array_merge(self::DEFAULTS, ['member', 'select', 'option', 'ref', 'T', 'hrefVariables']); if (!empty($this->element) && !in_array($this->element, $options)) { $this->description = '

Inherits from ' . $this->element . '

' . $this->description; } @@ -195,7 +201,7 @@ public function __toString(): string */ protected function construct_string_return(string $value): string { - if ($this->type === NULL) { + if ($this->type === null) { return $value; } diff --git a/src/PHPDraft/Model/Elements/RequestBodyElement.php b/src/PHPDraft/Model/Elements/RequestBodyElement.php index dd0efef4..7dfb059b 100644 --- a/src/PHPDraft/Model/Elements/RequestBodyElement.php +++ b/src/PHPDraft/Model/Elements/RequestBodyElement.php @@ -1,4 +1,5 @@ key = NULL; + $base1->key = null; $base1->value = [['Swift' => 'string'], ['Objective-C' => 'string']]; - $base1->status = NULL; + $base1->status = null; $base1->element = 'array'; - $base1->type = NULL; + $base1->type = null; $base1->is_variable = false; - $base1->description = NULL; + $base1->description = null; $base1->deps = []; $base2 = new ArrayStructureElement(); - $base2->key = NULL; + $base2->key = null; $base2->value = [['item' => 'string'], ['another item' => 'string']]; - $base2->status = NULL; + $base2->status = null; $base2->element = 'array'; $base2->type = 'Some simple array'; $base2->is_variable = false; - $base2->description = NULL; + $base2->description = null; $base2->deps = ['Some simple array']; $base3 = new ArrayStructureElement(); @@ -177,7 +177,7 @@ public function testToStringWithArray(): void */ public function testToStringWithComplexArray(): void { - $this->class->value = [['type'=>'Bike'], ['stuff'=>'car']]; + $this->class->value = [['type' => 'Bike'], ['stuff' => 'car']]; $return = $this->class->__toString(); $this->assertSame('', $return); } diff --git a/src/PHPDraft/Model/Elements/Tests/BasicStructureElementTest.php b/src/PHPDraft/Model/Elements/Tests/BasicStructureElementTest.php index 5cc9ec6f..eb806086 100644 --- a/src/PHPDraft/Model/Elements/Tests/BasicStructureElementTest.php +++ b/src/PHPDraft/Model/Elements/Tests/BasicStructureElementTest.php @@ -95,7 +95,7 @@ public function testParseCommonDeps(): void $answer = new ObjectStructureElement(); $answer->key = 'key'; $answer->type = 'cat'; - $answer->description = NULL; + $answer->description = null; $method = $this->reflection->getMethod('parse_common'); $method->setAccessible(true); diff --git a/src/PHPDraft/Model/Elements/Tests/EnumStructureElementTest.php b/src/PHPDraft/Model/Elements/Tests/EnumStructureElementTest.php index 7a2022be..65635bef 100644 --- a/src/PHPDraft/Model/Elements/Tests/EnumStructureElementTest.php +++ b/src/PHPDraft/Model/Elements/Tests/EnumStructureElementTest.php @@ -119,22 +119,22 @@ public function parseObjectProvider(): array { $return = []; $base1 = new EnumStructureElement(); - $base1->key = NULL; + $base1->key = null; $base1->value = [ 'item' => 'string', 'another item' => 'string']; - $base1->status = NULL; + $base1->status = null; $base1->element = 'enum'; $base1->type = 'Some simple enum'; $base1->is_variable = false; - $base1->description = NULL; + $base1->description = null; $base1->deps = ['Some simple enum']; $base2 = new EnumStructureElement(); $base2->key = 'car_id_list'; $base2->value = 'world'; - $base2->status = NULL; + $base2->status = null; $base2->element = 'enum'; $base2->type = 'string'; - $base2->description = NULL; + $base2->description = null; $base2->is_variable = false; $base2->deps = []; diff --git a/src/PHPDraft/Model/HTTPRequest.php b/src/PHPDraft/Model/HTTPRequest.php index 01d4dc31..77787d3d 100644 --- a/src/PHPDraft/Model/HTTPRequest.php +++ b/src/PHPDraft/Model/HTTPRequest.php @@ -1,4 +1,5 @@ parent->url_variables->value as $item) { $urlvalue = $item->value; if (is_subclass_of($item, BasicStructureElement::class)) { - $urlvalue = $item->string_value(TRUE); + $urlvalue = $item->string_value(true); } $vars[$item->key] = $urlvalue; diff --git a/src/PHPDraft/Out/BaseTemplateGenerator.php b/src/PHPDraft/Out/BaseTemplateGenerator.php index 9fe408b5..342adfea 100644 --- a/src/PHPDraft/Out/BaseTemplateGenerator.php +++ b/src/PHPDraft/Out/BaseTemplateGenerator.php @@ -1,4 +1,5 @@ + + + + + + + + \ No newline at end of file diff --git a/tests/statics/drafter/html/basic.html b/tests/statics/drafter/html/basic.html index e36f5aa9..8c9e8190 100644 --- a/tests/statics/drafter/html/basic.html +++ b/tests/statics/drafter/html/basic.html @@ -14,9 +14,9 @@

Tesla Model S JSON API https://owner-api.teslamotors.com

-

This is unofficial documentation of the Tesla Model S JSON API used by the iOS and Android apps. It features functionality to monitor and control the Model S remotely. +

This is unofficial documentation of the Tesla Model S JSON API used by the iOS and Android apps. It features functionality to monitor and control the Model S remotely.

-
+
diff --git a/tests/statics/drafter/html/material.html b/tests/statics/drafter/html/material.html index a0cefcd8..3dd059f7 100644 --- a/tests/statics/drafter/html/material.html +++ b/tests/statics/drafter/html/material.html @@ -2271,7 +2271,7 @@

CURL Command

+ readonly>curl -XPOST -H 'Authorization: Bearer {access_token}' 'https://owner-api.teslamotors.com/api/1/vehicles/1/command/sun_roof_control?state=%3Ctr%3E%3Ctd%3Eopen%3C%2Ftd%3E%3Ctd%3E%3Ccode%3Eenum%3C%2Fcode%3E%3C%2Ftd%3E%3Ctd%3E%3C%2Ftd%3E%3C%2Ftr%3E&percent=50'
@@ -2282,7 +2282,7 @@

CURL Command

id="request-panel-SOME_ID">
Example URI
https://owner-api.teslamotors.com - /api/1/vehicles/1/command/sun_roof_control?state=%3Ctr%3E%3Ctd%3Eopen%3C%2Ftd%3E%3Ctd%3E%3Ccode%3Eenum%3C%2Fcode%3E%3C%2Ftd%3E%3Ctd%3E%0A%3C%2Ftd%3E%3C%2Ftr%3E&percent=50 + /api/1/vehicles/1/command/sun_roof_control?state=%3Ctr%3E%3Ctd%3Eopen%3C%2Ftd%3E%3Ctd%3E%3Ccode%3Eenum%3C%2Fcode%3E%3C%2Ftd%3E%3Ctd%3E%3C%2Ftd%3E%3C%2Ftr%3E&percent=50
Headers