Completed
Pull Request — 2.x (#41)
by jake
02:03
created

AbstractElement   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 50
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
__invoke() 0 1 ?
A escaped() 0 8 2
A raw() 0 8 2
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Html\Helper;
10
11
/**
12
 *
13
 * Helper to generate a complete element.
14
 *
15
 * @package Aura.Html
16
 *
17
 */
18
abstract class AbstractElement extends AbstractHelper
19
{
20
21
22
    abstract public function __invoke($tag, $content, array $attr = array());
23
24
    /**
25
     *
26
     * Returns any kind of complete HTML element with attributes and escaped content.
27
     *
28
     * @param string $tag The tag to generate.
29
     *
30
     * @param string $content The element content
31
     *
32
     * @param array $attr Attributes for the tag.
33
     *
34
     * @return string
35
     *
36
     */
37 4
    protected function escaped($tag, $content, array $attr = array())
38
    {
39 4
        $attr = $this->escaper->attr($attr);
40 4
        $out = $attr ? "<{$tag} $attr>" : "<{$tag}>";
41 4
        $out .= $this->escaper->html($content);
42 4
        $out .= "</$tag>";
43 4
        return $out;
44
    }
45
46
    /**
47
     *
48
     * Returns any kind of complete HTML element with attributes.
49
     *
50
     * @param string $tag The tag to generate.
51
     *
52
     * @param string $content The content of the element.
53
     *
54
     * @param array $attr Attributes for the tag.
55
     *
56
     * @return string
57
     *
58
     */
59 6
    public function raw($tag, $content, array $attr = array())
60
    {
61 6
        $attr = $this->escaper->attr($attr);
62 6
        $out = $attr ? "<{$tag} $attr>" : "<{$tag}>";
63 6
        $out .= $content;
64 6
        $out .= "</$tag>";
65 6
        return $out;
66
    }
67
}
68