AntiXssExtension::getFunctions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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