Completed
Push — master ( f9734a...270a77 )
by Billie
04:39 queued 02:11
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
     * @see        https://github.com/PurpleBooth/htmlstrip
53
     * @deprecated v1.1.0 This will be removed in the future, please use the PurpleBooth/htmlstrip library
54
     *
55
     * @param string $html
56
     *
57
     * @return string
58
     */
59 1
    public function toText($html)
60
    {
61 1
        return $this->htmlStripper->toText($html);
62
    }
63
}
64