Passed
Push — html-helpers ( eca32d...09239a )
by Nikolaos
04:43
created

AbstractSeries::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
/**
4
 * This file is part of the Phalcon Framework.
5
 *
6
 * For the full copyright and license information, please view the LICENSE.md
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Phalcon\Html\Helper;
13
14
use Phalcon\Html\Exception;
15
16
/**
17
 * Class AbstractSeries
18
 *
19
 * @property array  $attributes
20
 * @property string $delimiter
21
 * @property string $indent
22
 * @property array  $store
23
 */
24
abstract class AbstractSeries extends AbstractHelper
25
{
26
    /**
27
     * @var array
28
     */
29
    protected $attributes = [];
30
31
    /**
32
     * @var string
33
     */
34
    protected $delimiter = PHP_EOL;
35
36
    /**
37
     * @var string
38
     */
39
    protected $indent = "    ";
40
41
    /**
42
     * @var array
43
     */
44
    protected $store = [];
45
46
    /**
47
     * @param string $indent
48
     * @param string $delimiter
49
     *
50
     * @return AbstractSeries
51
     */
52 9
    public function __invoke(
53
        string $indent = null,
54
        string $delimiter = null
55
    ): AbstractSeries {
56 9
        if (null !== $delimiter) {
57 3
            $this->delimiter = $delimiter;
58
        }
59
60 9
        if (null !== $indent) {
61 3
            $this->indent = $indent;
62
        }
63
64 9
        $this->store = [];
65
66 9
        return $this;
67
    }
68
69
    /**
70
     * Generates and returns the HTML for the list.
71
     *
72
     * @return string
73
     */
74 9
    public function __toString()
75
    {
76 9
        if (empty($this->store)) {
77 3
            return "";
78
        }
79
80 6
        return implode($this->delimiter, $this->store) . $this->delimiter;
81
    }
82
83
    /**
84
     * Returns the tag name.
85
     *
86
     * @return string
87
     */
88
    abstract protected function getTag(): string;
89
}
90