Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
artyuum committed May 12, 2021
1 parent 5abd9ac commit ec565ab
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ composer.lock

# PHPCS
php_cs.cache

# PHPUnit
.phpunit.result.cache
10 changes: 8 additions & 2 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,4 +34,5 @@ return PhpCsFixer\Config::create()
->setIndent(str_pad('', 4))
->setFinder(
$finder
);
)
;
14 changes: 0 additions & 14 deletions src/HtmlElement/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ';')
{
Expand Down Expand Up @@ -86,10 +84,6 @@ public function getName(): ?string

/**
* Sets the name.
*
* @param string $name
*
* @return self
*/
public function setName(string $name): self
{
Expand All @@ -112,7 +106,6 @@ public function getValue()
* Sets the value.
*
* @param mixed $value
* @return self
*/
public function setValue($value): self
{
Expand All @@ -125,8 +118,6 @@ public function setValue($value): self

/**
* Gets the separator.
*
* @return string
*/
public function getSeparator(): string
{
Expand All @@ -135,9 +126,6 @@ public function getSeparator(): string

/**
* Sets the attribute values separator.
*
* @param string $separator
* @return self
*/
public function setSeparator(string $separator): self
{
Expand All @@ -148,8 +136,6 @@ public function setSeparator(string $separator): self

/**
* Builds & returns the HTML representation of the attribute.
*
* @return string
*/
public function build(): string
{
Expand Down
40 changes: 7 additions & 33 deletions src/HtmlElement/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Artyum\HtmlElement;

use InvalidArgumentException;
use Artyum\HtmlElement\Exceptions\SelfClosingTagException;
use InvalidArgumentException;
use LogicException;

/**
Expand All @@ -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',
Expand All @@ -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
Expand All @@ -67,8 +63,6 @@ public function __construct(?string $name = null, ?array $options = null)

/**
* Gets the generated HTML.
*
* @return string
*/
public function __toString(): string
{
Expand All @@ -77,8 +71,6 @@ public function __toString(): string

/**
* Gets the element start tag.
*
* @return string
*/
private function startTag(): string
{
Expand All @@ -94,8 +86,6 @@ private function startTag(): string

/**
* Builds the element's attributes.
*
* @return string|null
*/
private function buildAttributes(): ?string
{
Expand All @@ -114,8 +104,6 @@ private function buildAttributes(): ?string

/**
* Gets the element end tag.
*
* @return string
*/
private function endTag(): ?string
{
Expand All @@ -129,8 +117,6 @@ private function endTag(): ?string

/**
* Checks if the element is a self-closing tag.
*
* @return bool
*/
private function isSelfClosingTag(): bool
{
Expand All @@ -139,8 +125,6 @@ private function isSelfClosingTag(): bool

/**
* Gets the name of the element.
*
* @return string
*/
public function getName(): string
{
Expand All @@ -149,8 +133,6 @@ public function getName(): string

/**
* Sets the name of the element.
*
* @return self
*/
public function setName(string $name): self
{
Expand All @@ -161,8 +143,6 @@ public function setName(string $name): self

/**
* Gets the options.
*
* @return array|null
*/
public function getOptions(): ?array
{
Expand All @@ -171,9 +151,6 @@ public function getOptions(): ?array

/**
* Sets the options.
*
* @param array $options
* @return self
*/
public function setOptions(array $options): self
{
Expand All @@ -196,7 +173,6 @@ public function getAttributes(): ?array
* Adds attributes to the element.
*
* @param Attribute ...$attributes
* @return $this
*/
public function addAttributes(...$attributes): self
{
Expand All @@ -214,8 +190,6 @@ public function addAttributes(...$attributes): self

/**
* Gets the element content.
*
* @return string|null
*/
public function getContent(): ?string
{
Expand All @@ -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
*/
Expand Down
5 changes: 2 additions & 3 deletions tests/HtmlElement/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Tests\HtmlElement;

use Artyum\HtmlElement\Attribute;
use Artyum\HtmlElement\Element;
use InvalidArgumentException;
use LogicException;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -67,7 +66,7 @@ public function testDefaultSeparator()
{
$attribute = new Attribute('test', [
'first',
'second'
'second',
]);

$this->assertEquals(
Expand All @@ -83,7 +82,7 @@ public function testCustomSeparator()
{
$attribute = new Attribute('test', [
'first',
'second'
'second',
], ' ');

$this->assertEquals(
Expand Down
4 changes: 2 additions & 2 deletions tests/HtmlElement/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,7 +68,7 @@ public function testElementWithAttributes()
new Attribute('title', 'test'),
new Attribute('style', [
'width: 100px',
'height: 100px'
'height: 100px',
])
)
->toHtml()
Expand Down

0 comments on commit ec565ab

Please sign in to comment.