AntiXssExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 4
dl 0
loc 68
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A xss_clean() 0 4 1
A getFilters() 0 6 1
A getFunctions() 0 6 1
A getTokenParsers() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace voku\twig;
6
7
use voku\helper\AntiXSS;
8
9
/**
10
 * Class AntiXssExtension
11
 */
12
class AntiXssExtension extends \Twig_Extension
13
{
14
  /**
15
   * @var array
16
   */
17
  private $options = [
18
      'is_safe'           => ['html'],
19
      'needs_environment' => false,
20
  ];
21
22
  /**
23
   * @var callable
24
   */
25
  private $callable;
26
27
  /**
28
   * @var AntiXss
29
   */
30
  private $antiXss;
31
32
  /**
33
   * AntiXssExtension constructor.
34
   *
35
   * @param AntiXSS $antiXss
36
   */
37 6
  public function __construct(AntiXSS $antiXss)
38
  {
39 6
    $this->antiXss = $antiXss;
0 ignored issues
show
Documentation Bug introduced by
It seems like $antiXss of type object<voku\helper\AntiXSS> is incompatible with the declared type object<voku\twig\AntiXss> of property $antiXss.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40 6
    $this->callable = [$this, 'xss_clean'];
41 6
  }
42
43
  /**
44
   * @param string $html
45
   *
46
   * @return mixed
47
   */
48 6
  public function xss_clean($html)
49
  {
50 6
    return $this->antiXss->xss_clean($html);
51
  }
52
53
  /** @noinspection PhpMissingParentCallCommonInspection */
54
  /**
55
   * @return array
56
   */
57 6
  public function getFilters(): array
58
  {
59
    return [
60 6
        new \Twig_SimpleFilter('xss_clean', $this->callable, $this->options),
61
    ];
62
  }
63
64
  /** @noinspection PhpMissingParentCallCommonInspection */
65 6
  public function getFunctions(): array
66
  {
67
    return [
68 6
        new \Twig_SimpleFunction('xss_clean', $this->callable, $this->options),
69
    ];
70
  }
71
72
  /** @noinspection PhpMissingParentCallCommonInspection */
73 6
  public function getTokenParsers(): array
74
  {
75
    return [
76 6
        new AntiXssTokenParser(),
77
    ];
78
  }
79
}
80