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

Style::getAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 1
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 Styles
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 4
    public function add(string $href, array $attributes = [])
32
    {
33 4
        $this->store[] = $this->indent
34 4
            . $this->renderFullElement(
35 4
                $this->getTag(),
36 4
                '',
37 4
                $this->getAttributes($href, $attributes)
38
            )
39
        ;
40
41 4
        return $this;
42
    }
43
44
    /**
45
     * @return string
46
     */
47 2
    protected function getTag(): string
48
    {
49 2
        return 'style';
50
    }
51
52
    /**
53
     * Returns the necessary attributes
54
     *
55
     * @param string $attribute
56
     * @param array  $attributes
57
     *
58
     * @return array
59
     */
60 2
    protected function getAttributes(string $attribute, array $attributes): array
61
    {
62
        $required = [
63 2
            'rel'   => 'stylesheet',
64 2
            'href'  => $attribute,
65 2
            'type'  => 'text/css',
66 2
            'media' => 'screen',
67
        ];
68
69 2
        unset($attributes["href"]);
70
71 2
        return array_merge($required, $attributes);
72
    }
73
}
74