Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Apr 21, 2020
1 parent 5df8fd5 commit 8e4556a
Show file tree
Hide file tree
Showing 37 changed files with 104 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 20 additions & 31 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/PHPDraft/Core/Autoloader.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
3 changes: 1 addition & 2 deletions src/PHPDraft/In/ApibFileParser.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
declare(strict_types=1);
<?php declare(strict_types=1);

/**
* This file contains the ApibFileParser.
Expand Down
6 changes: 3 additions & 3 deletions src/PHPDraft/In/Tests/ApibFileParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public function testParseBasic(): void
$full_property->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));
Expand Down
1 change: 1 addition & 0 deletions src/PHPDraft/Model/Category.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions src/PHPDraft/Model/Comparable.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
3 changes: 2 additions & 1 deletion src/PHPDraft/Model/Elements/ArrayStructureElement.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down Expand Up @@ -42,7 +43,7 @@ public function parse(?object $object, array &$dependencies): StructureElement
}

$key = $sub_item->element ?? 'any';
$value = $sub_item->content ?? NULL;
$value = $sub_item->content ?? null;
$this->value[] = [$value => $key];
}

Expand Down
11 changes: 6 additions & 5 deletions src/PHPDraft/Model/Elements/BasicStructureElement.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down Expand Up @@ -112,7 +113,7 @@ protected function parse_common(object $object, array &$dependencies): void
$this->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);
}

Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/PHPDraft/Model/Elements/EnumStructureElement.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down Expand Up @@ -27,8 +28,8 @@ public function parse(?object $object, array &$dependencies): StructureElement

$this->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;
Expand Down
16 changes: 11 additions & 5 deletions src/PHPDraft/Model/Elements/ObjectStructureElement.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand All @@ -23,7 +24,10 @@ class ObjectStructureElement extends BasicStructureElement
* Unset object function.
* @internal Only for tests
*/
public function __clearForTest(){$this->object = NULL;}
public function __clearForTest()
{
$this->object = null;
}

/**
* Parse a JSON object to a data structure.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
*/
Expand All @@ -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 = '<p>Inherits from <a href="#object-' . strtolower($this->element) . '">' . $this->element . '</a></p>' . $this->description;
}
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/PHPDraft/Model/Elements/RequestBodyElement.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
3 changes: 2 additions & 1 deletion src/PHPDraft/Model/Elements/StructureElement.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down Expand Up @@ -45,5 +46,5 @@ public function __toString(): string;
*
* @return string
*/
public function string_value($flat = FALSE);
public function string_value($flat = false);
}
16 changes: 8 additions & 8 deletions src/PHPDraft/Model/Elements/Tests/ArrayStructureElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ public function parseObjectProvider(): array
{
$return = [];
$base1 = new ArrayStructureElement();
$base1->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();
Expand Down Expand Up @@ -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('<ul class="list-group mdl-list"><li class="list-group-item mdl-list__item"><a class="code" title="Bike" href="#object-bike">Bike</a> - <span class="example-value pull-right">type</span></li><li class="list-group-item mdl-list__item"><a class="code" title="car" href="#object-car">car</a> - <span class="example-value pull-right">stuff</span></li></ul>', $return);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 8e4556a

Please sign in to comment.