Completed
Push — master ( f9734a...270a77 )
by Billie
04:39 queued 02:11
created

HtmlStripperExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

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 4
dl 0
loc 54
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
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