Passed
Push — master ( 2afdeb...b846a2 )
by Nikolaos
06:23 queued 03:51
created

AbstractList::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 17
ccs 11
cts 11
cp 1
crap 2
rs 9.9
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 AbstractList
18
 *
19
 * @property array  $attributes
20
 * @property string $elementTag
21
 * @property array  $store
22
 */
23
abstract class AbstractList extends AbstractHelper
24
{
25
    /**
26
     * @var array
27
     */
28
    protected $attributes = [];
29
30
    /**
31
     * @var string
32
     */
33
    protected $elementTag = "li";
34
35
    /**
36
     * @var array
37
     */
38
    protected $store = [];
39
40
    /**
41
     * @param string $indent
42
     * @param string $delimiter
43
     * @param array  $attributes
44
     *
45
     * @return AbstractList
46
     */
47 4
    public function __invoke(
48
        string $indent = null,
49
        string $delimiter = null,
50
        array $attributes = []
51
    ): AbstractList {
52 4
        $this->attributes = $attributes;
53 4
        if (null !== $delimiter) {
54 3
            $this->delimiter = $delimiter;
55
        }
56
57 4
        if (null !== $indent) {
58 3
            $this->indent = $indent;
59
        }
60
61 4
        $this->store = [];
62
63 4
        return $this;
64
    }
65
66
    /**
67
     * Generates and returns the HTML for the list.
68
     *
69
     * @return string
70
     * @throws Exception
71
     */
72 4
    public function __toString()
73
    {
74 4
        if (empty($this->store)) {
75 1
            return "";
76
        }
77
78 3
        $contents = $this->delimiter .
79 3
            $this->renderArrayElements(
80 3
                $this->store,
81 3
                $this->delimiter
82
            );
83
84 3
        return $this->renderFullElement(
85 3
            $this->getTag(),
86
            $contents,
87 3
            $this->attributes,
88 3
            true
89
        );
90
    }
91
92
    /**
93
     *
94
     * Returns the tag name.
95
     *
96
     * @return string
97
     *
98
     */
99
    abstract protected function getTag();
100
}
101