AttributeNode::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 4
c 1
b 0
f 0
nc 8
nop 4
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 4
rs 10
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