Completed
Pull Request — 2.x (#43)
by jake
02:49 queued 50s
created

EscaperFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 40%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 2
c 4
b 0
f 2
lcom 1
cbo 5
dl 0
loc 55
ccs 4
cts 10
cp 0.4
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A newInstance() 0 8 1
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Html;
10
11
use Aura\Html\Escaper;
12
use Aura\Html\Escaper\HtmlEscaper;
13
use Aura\Html\Escaper\AttrEscaper;
14
use Aura\Html\Escaper\CssEscaper;
15
use Aura\Html\Escaper\JsEscaper;
16
17
/**
18
 *
19
 * Factory to create an Escaper object.
20
 *
21
 * @package Aura.Html
22
 *
23
 */
24
class EscaperFactory
25
{
26
    /**
27
     *
28
     * The encoding for the escapers.
29
     *
30
     * @var string
31
     *
32
     */
33
    protected $encoding;
34
35
    /**
36
     *
37
     * The `htmlspecialchars()` flags for the escapers.
38
     *
39
     * @var int
40
     *
41
     */
42
    protected $flags;
43
44
    /**
45
     *
46
     * Constructor.
47
     *
48
     * @param string $encoding The encoding for the escapers.
49
     *
50
     * @param int $flags The `htmlspecialchars()` flags for the escapers.
51
     *
52
     */
53 85
    public function __construct($encoding = null, $flags = null)
54
    {
55 85
        $this->encoding = $encoding;
56 85
        $this->flags = $flags;
57 1
    }
58
59
    /**
60
     *
61
     * Creates a new Escaper object.
62
     *
63
     * @param string $encoding The encoding for the escapers.
0 ignored issues
show
Bug introduced by
There is no parameter named $encoding. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
64
     *
65
     * @param int $flags The `htmlspecialchars()` flags for the escapers.
0 ignored issues
show
Bug introduced by
There is no parameter named $flags. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
66
     *
67
     * @return Escaper
68
     *
69
     */
70
    public function newInstance()
71
    {
72
        $html = new HtmlEscaper($this->flags, $this->encoding);
73
        $attr = new AttrEscaper($html, $this->encoding);
74
        $css = new CssEscaper($this->encoding);
75
        $js = new JsEscaper($this->encoding);
76
        return new Escaper($html, $attr, $css, $js);
77
    }
78
}
79