Completed
Pull Request — master (#12)
by Billie
05:53 queued 01:59
created

HtmlStripperExtension::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 4
ccs 2
cts 2
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
    private $htmlStripper;
13
14
    /**
15
     * HtmlStripperExtension constructor.
16
     */
17 3
    public function __construct()
18
    {
19 3
        $this->htmlStripper = new HtmlStripper();
20 3
    }
21
22
23
    /**
24
     * This gets an array of the filters that this extension provides
25
     *
26
     * @return \Twig_SimpleFilter[]
27
     */
28
    public function getFilters()
29
    {
30
        return [
31
            new \Twig_SimpleFilter('html_strip', [$this->htmlStripper, 'toText']),
32
        ];
33
    }
34
35
    /**
36
     * A convenient name for this extension
37
     *
38
     * @return string
39
     */
40 1
    public function getName()
41
    {
42 1
        return "html_stripper";
43
    }
44
45
    /**
46
     * This is the extension itself, it's mostly a small wrapper around the actual parser.
47
     *
48
     * @param string $html
49
     *
50
     * @return string
51
     */
52 1
    public function toText($html)
53
    {
54 1
        return $this->htmlStripper->toText($html);
55
    }
56
}
57