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

Style   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 55
ccs 17
cts 17
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttributes() 0 12 1
A add() 0 13 1
A getTag() 0 3 1
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 Style
18
 */
19
class Style extends AbstractSeries
20
{
21
22
    /**
23
     * Add an element to the list
24
     *
25
     * @param string $href
26
     * @param array  $attributes
27
     *
28
     * @return $this
29
     * @throws Exception
30
     */
31 2
    public function add(string $href, array $attributes = [])
32
    {
33 2
        $this->store[] = [
34 2
            "renderFullElement",
35
            [
36 2
                $this->getTag(),
37 2
                '',
38 2
                $this->getAttributes($href, $attributes),
39
            ],
40 2
            $this->indent(),
41
        ];
42
43 2
        return $this;
44
    }
45
46
    /**
47
     * @return string
48
     */
49 1
    protected function getTag(): string
50
    {
51 1
        return 'style';
52
    }
53
54
    /**
55
     * Returns the necessary attributes
56
     *
57
     * @param string $href
58
     * @param array  $attributes
59
     *
60
     * @return array
61
     */
62 1
    protected function getAttributes(string $href, array $attributes): array
63
    {
64
        $required = [
65 1
            'rel'   => 'stylesheet',
66 1
            'href'  => $href,
67 1
            'type'  => 'text/css',
68 1
            'media' => 'screen',
69
        ];
70
71 1
        unset($attributes["href"]);
72
73 1
        return array_merge($required, $attributes);
74
    }
75
}
76