RenderAwareMethods::render()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * This file is part of slick/form package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Form\Element;
11
12
use Slick\Form\Renderer\RendererInterface;
13
14
/**
15
 * Render capabilities for HTML elements
16
 *
17
 * @package Slick\Form\Element
18
 * @author  Filipe Silva <[email protected]>
19
 */
20
trait RenderAwareMethods
21
{
22
23
    /**
24
     * Returns the HTML string for current element
25
     *
26
     * @param array $context
27
     *
28
     * @return string
29
     */
30 20
    public function render($context = [])
31
    {
32 20
        $this->getRenderer()->setElement($this);
33 20
        return $this->getRenderer()->render($context);
34
    }
35
36
    /**
37
     * Returns the HTML string for this element
38
     *
39
     * @return string
40
     */
41 16
    public function __toString()
42
    {
43 16
        return (string) $this->render();
44
    }
45
46
    /**
47
     * Gets the HTML renderer for this element
48
     *
49
     * @return RendererInterface
50
     */
51
    abstract protected function getRenderer();
52
53
}