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

AbstractElement::raw()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4286
cc 2
eloc 6
nc 2
nop 3
crap 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