AntiXssTokenParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A decideAntiXssEnd() 0 4 1
A getTag() 0 4 1
A parse() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace voku\twig;
6
7
use Twig_Token;
8
use Twig_TokenParser;
9
10
/**
11
 * Class AntiXssTokenParser
12
 */
13
class AntiXssTokenParser extends Twig_TokenParser
14
{
15
  /**
16
   * @param Twig_Token $token
17
   *
18
   * @return bool
19
   */
20 2
  public function decideAntiXssEnd(Twig_Token $token): bool
21
  {
22 2
    return $token->test('end_xss_clean');
23
  }
24
25
  /** @noinspection PhpMissingParentCallCommonInspection */
26 6
  public function getTag(): string
27
  {
28 6
    return 'xss_clean';
29
  }
30
31
  /**
32
   * @param Twig_Token $token
33
   *
34
   * @return AntiXssNode
35
   */
36 2
  public function parse(Twig_Token $token): AntiXssNode
37
  {
38 2
    $lineNumber = $token->getLine();
39 2
    $stream = $this->parser->getStream();
40 2
    $stream->expect(Twig_Token::BLOCK_END_TYPE);
41 2
    $body = $this->parser->subparse([$this, 'decideAntiXssEnd'], true);
42 2
    $stream->expect(Twig_Token::BLOCK_END_TYPE);
43 2
    $nodes = ['body' => $body];
44
45 2
    return new AntiXssNode($nodes, [], $lineNumber, $this->getTag());
46
  }
47
}
48