Completed
Pull Request — master (#12)
by Billie
03:27
created

HtmlStripperExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PurpleBooth;
4
5
/**
6
 * This is sets up the twig extension
7
 *
8
 * @package PurpleBooth
9
 */
10
class HtmlStripperExtension extends \Twig_Extension
11
{
12
13
    /**
14
     * @var HtmlStripper
15
     */
16
    private $htmlStripper;
17
18
    /**
19
     * HtmlStripperExtension constructor.
20
     */
21 3
    public function __construct()
22
    {
23 3
        $this->htmlStripper = new HtmlStripperImplementation();
24 3
    }
25
26
27
    /**
28
     * This gets an array of the filters that this extension provides
29
     *
30
     * @return \Twig_SimpleFilter[]
31
     */
32
    public function getFilters()
33
    {
34
        return [
35
            new \Twig_SimpleFilter('html_strip', [$this->htmlStripper, 'toText']),
36
        ];
37
    }
38
39
    /**
40
     * A convenient name for this extension
41
     *
42
     * @return string
43
     */
44 1
    public function getName()
45
    {
46 1
        return "html_stripper";
47
    }
48
49
    /**
50
     * This is the extension itself, it's mostly a small wrapper around the actual parser.
51
     *
52
     * @param string $html
53
     *
54
     * @return string
55
     */
56 1
    public function toText($html)
57
    {
58 1
        return $this->htmlStripper->toText($html);
59
    }
60
}
61