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

Anchor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 40
ccs 7
cts 7
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 9 1
A processAttributes() 0 10 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 Anchor
18
 */
19
class Anchor extends AbstractHelper
20
{
21
    /**
22
     * Produce a <a> tag
23
     *
24
     * @param string $href
25
     * @param string $text
26
     * @param array  $attributes
27
     * @param bool   $raw
28
     *
29
     * @return string
30
     * @throws Exception
31
     */
32 1
    public function __invoke(
33
        string $href,
34
        string $text,
35
        array $attributes = [],
36
        bool $raw = false
37
    ): string {
38 1
        $overrides = $this->processAttributes($href, $attributes);
39
40 1
        return $this->renderFullElement("a", $text, $overrides, $raw);
41
    }
42
43
    /**
44
     * @param string $href
45
     * @param array  $attributes
46
     *
47
     * @return array
48
     */
49 1
    protected function processAttributes(string $href, array $attributes): array
50
    {
51 1
        $overrides = ["href" => $href];
52
53
        /**
54
         * Avoid duplicate "href" and ignore it if it is passed in the attributes
55
         */
56 1
        unset($attributes["href"]);
57
58 1
        return array_merge($overrides, $attributes);
59
    }
60
}
61