From ec565ab8c72f7da0b34469c1a1a6d4e34c245370 Mon Sep 17 00:00:00 2001 From: Artyum Petrov Date: Thu, 13 May 2021 00:44:47 +0400 Subject: [PATCH] CS --- .gitignore | 3 +++ .php_cs.dist | 10 ++++++-- src/HtmlElement/Attribute.php | 14 ---------- src/HtmlElement/Element.php | 40 +++++------------------------ tests/HtmlElement/AttributeTest.php | 5 ++-- tests/HtmlElement/ElementTest.php | 4 +-- 6 files changed, 22 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index af3b985..fb41ed3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ composer.lock # PHPCS php_cs.cache + +# PHPUnit +.phpunit.result.cache diff --git a/.php_cs.dist b/.php_cs.dist index 22d7fb0..2ce0a06 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -9,7 +9,12 @@ return PhpCsFixer\Config::create() ->setCacheFile(__DIR__ . '/php_cs.cache') ->setRiskyAllowed(true) ->setRules([ - '@PSR2' => true, + '@Symfony' => true, + 'yoda_style' => [ + 'equal' => false, + 'identical' => false, + 'less_and_greater' => false, + ], 'array_indentation' => true, 'method_chaining_indentation' => true, 'no_useless_else' => true, @@ -29,4 +34,5 @@ return PhpCsFixer\Config::create() ->setIndent(str_pad('', 4)) ->setFinder( $finder - ); + ) +; diff --git a/src/HtmlElement/Attribute.php b/src/HtmlElement/Attribute.php index d3e6ba0..e797045 100644 --- a/src/HtmlElement/Attribute.php +++ b/src/HtmlElement/Attribute.php @@ -26,9 +26,7 @@ class Attribute private string $separator; /** - * @param string|null $name * @param mixed $value - * @param string $separator */ public function __construct(?string $name = null, $value = null, string $separator = ';') { @@ -86,10 +84,6 @@ public function getName(): ?string /** * Sets the name. - * - * @param string $name - * - * @return self */ public function setName(string $name): self { @@ -112,7 +106,6 @@ public function getValue() * Sets the value. * * @param mixed $value - * @return self */ public function setValue($value): self { @@ -125,8 +118,6 @@ public function setValue($value): self /** * Gets the separator. - * - * @return string */ public function getSeparator(): string { @@ -135,9 +126,6 @@ public function getSeparator(): string /** * Sets the attribute values separator. - * - * @param string $separator - * @return self */ public function setSeparator(string $separator): self { @@ -148,8 +136,6 @@ public function setSeparator(string $separator): self /** * Builds & returns the HTML representation of the attribute. - * - * @return string */ public function build(): string { diff --git a/src/HtmlElement/Element.php b/src/HtmlElement/Element.php index 971afc0..03c06a8 100644 --- a/src/HtmlElement/Element.php +++ b/src/HtmlElement/Element.php @@ -2,8 +2,8 @@ namespace Artyum\HtmlElement; -use InvalidArgumentException; use Artyum\HtmlElement\Exceptions\SelfClosingTagException; +use InvalidArgumentException; use LogicException; /** @@ -12,27 +12,27 @@ class Element { /** - * @var string Should contain the name of the HTML element to create. + * @var string should contain the name of the HTML element to create */ private ?string $name = null; /** - * @var array|null Should contain an array of options. + * @var array|null should contain an array of options */ private ?array $options; /** - * @var string|null Should contain the content of the element. + * @var string|null should contain the content of the element */ private ?string $content = null; /** - * @var Attribute[] Should contain an array of Attribute class instances. + * @var Attribute[] should contain an array of Attribute class instances */ private array $attributes = []; /** - * @var array Should contain an array of self-closing HTML tags. + * @var array should contain an array of self-closing HTML tags */ private $selfClosingTags = [ 'area', @@ -51,10 +51,6 @@ class Element 'wbr', ]; - /** - * @param string|null $name - * @param array|null $options - */ public function __construct(?string $name = null, ?array $options = null) { // prevents transforming $name into an empty string if not set @@ -67,8 +63,6 @@ public function __construct(?string $name = null, ?array $options = null) /** * Gets the generated HTML. - * - * @return string */ public function __toString(): string { @@ -77,8 +71,6 @@ public function __toString(): string /** * Gets the element start tag. - * - * @return string */ private function startTag(): string { @@ -94,8 +86,6 @@ private function startTag(): string /** * Builds the element's attributes. - * - * @return string|null */ private function buildAttributes(): ?string { @@ -114,8 +104,6 @@ private function buildAttributes(): ?string /** * Gets the element end tag. - * - * @return string */ private function endTag(): ?string { @@ -129,8 +117,6 @@ private function endTag(): ?string /** * Checks if the element is a self-closing tag. - * - * @return bool */ private function isSelfClosingTag(): bool { @@ -139,8 +125,6 @@ private function isSelfClosingTag(): bool /** * Gets the name of the element. - * - * @return string */ public function getName(): string { @@ -149,8 +133,6 @@ public function getName(): string /** * Sets the name of the element. - * - * @return self */ public function setName(string $name): self { @@ -161,8 +143,6 @@ public function setName(string $name): self /** * Gets the options. - * - * @return array|null */ public function getOptions(): ?array { @@ -171,9 +151,6 @@ public function getOptions(): ?array /** * Sets the options. - * - * @param array $options - * @return self */ public function setOptions(array $options): self { @@ -196,7 +173,6 @@ public function getAttributes(): ?array * Adds attributes to the element. * * @param Attribute ...$attributes - * @return $this */ public function addAttributes(...$attributes): self { @@ -214,8 +190,6 @@ public function addAttributes(...$attributes): self /** * Gets the element content. - * - * @return string|null */ public function getContent(): ?string { @@ -226,7 +200,7 @@ public function getContent(): ?string * Adds content to the element. * * @param int|float|string|bool|self ...$content - * @return self + * * @throws SelfClosingTagException * @throws InvalidArgumentException */ diff --git a/tests/HtmlElement/AttributeTest.php b/tests/HtmlElement/AttributeTest.php index 1902d98..b0b4683 100644 --- a/tests/HtmlElement/AttributeTest.php +++ b/tests/HtmlElement/AttributeTest.php @@ -3,7 +3,6 @@ namespace Tests\HtmlElement; use Artyum\HtmlElement\Attribute; -use Artyum\HtmlElement\Element; use InvalidArgumentException; use LogicException; use PHPUnit\Framework\TestCase; @@ -67,7 +66,7 @@ public function testDefaultSeparator() { $attribute = new Attribute('test', [ 'first', - 'second' + 'second', ]); $this->assertEquals( @@ -83,7 +82,7 @@ public function testCustomSeparator() { $attribute = new Attribute('test', [ 'first', - 'second' + 'second', ], ' '); $this->assertEquals( diff --git a/tests/HtmlElement/ElementTest.php b/tests/HtmlElement/ElementTest.php index fadc432..4a93326 100644 --- a/tests/HtmlElement/ElementTest.php +++ b/tests/HtmlElement/ElementTest.php @@ -3,8 +3,8 @@ namespace Tests\HtmlElement; use Artyum\HtmlElement\Attribute; -use Artyum\HtmlElement\Exceptions\SelfClosingTagException; use Artyum\HtmlElement\Element; +use Artyum\HtmlElement\Exceptions\SelfClosingTagException; use InvalidArgumentException; use LogicException; use PHPUnit\Framework\TestCase; @@ -68,7 +68,7 @@ public function testElementWithAttributes() new Attribute('title', 'test'), new Attribute('style', [ 'width: 100px', - 'height: 100px' + 'height: 100px', ]) ) ->toHtml()