AttributeNode   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 26
ccs 9
cts 9
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 7 2
A __construct() 0 6 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Biurad opensource projects.
7
 *
8
 * PHP version 7.2 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 Biurad Group (https://biurad.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Biurad\UI\Html\Node;
19
20
class AttributeNode extends AbstractNode
21
{
22
    /** @var string @read-only */
23
    public $name, $space, $quote;
24
25
    /** @var string|null */
26
    public $value;
27
28
    /** @var SelfCloseNode|ElementNode|null */
29
    public $node;
30
31 1
    public function __construct(string $name, ?string $value = null, string $space = ' ', bool $noQuote = false)
32
    {
33 1
        $this->name = $name;
34 1
        $this->value = $value;
35 1
        $this->space = $space;
36 1
        $this->quote = $noQuote ? '' : (null !== $value && \str_contains($value, '"') ? '\'' : '"');
37
    }
38
39 1
    public function __toString(): string
40
    {
41 1
        if (null === $value = $this->value) {
42 1
            return $this->space . $this->name;
43
        }
44
45 1
        return $this->space . $this->name . '=' . $this->quote . $value . $this->quote;
46
    }
47
}
48