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

HtmlStripperExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 77.78%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 4
c 4
b 1
f 1
lcom 1
cbo 3
dl 0
loc 47
ccs 7
cts 9
cp 0.7778
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFilters() 0 6 1
A getName() 0 4 1
A toText() 0 4 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