Passed
Push — master ( 2afdeb...b846a2 )
by Nikolaos
06:23 queued 03:51
created

Escaper::getDoubleEncode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
/**
4
 * This file is part of the Phalcon Framework.
5
 *
6
 * For the full copyright and license information, please view the LICENSE.md
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Phalcon\Html;
13
14
/**
15
 * Class Escaper
16
 *
17
 * @property bool   $doubleEncode
18
 * @property string $encoding
19
 * @property int    $flags
20
 */
21
class Escaper
22
{
23
    /**
24
     * @var bool
25
     */
26
    protected $doubleEncode = true;
27
28
    /**
29
     * @var string
30
     */
31
    protected $encoding = "utf-8";
32
33
    /**
34
     * @var int
35
     */
36
    protected $flags = ENT_QUOTES;
37
38
    /**
39
     * Escaper constructor.
40
     */
41 27
    public function __construct()
42
    {
43 27
        $this->flags = ENT_QUOTES | ENT_SUBSTITUTE;
44 27
    }
45
46
    /**
47
     * Escape HTML attributes
48
     *
49
     * @param string $input
50
     *
51
     * @return string
52
     */
53 20
    public function attributes(string $input): string
54
    {
55 20
        return $input;
56
    }
57
58
    /**
59
     * Escape CSS
60
     *
61
     * @param string $input
62
     *
63
     * @return string
64
     */
65
    public function css(string $input): string
66
    {
67
        return $input;
68
    }
69
70
    /**
71
     * Returns whether we will use double encoding or not
72
     *
73
     * @return bool
74
     */
75
    public function getDoubleEncode(): bool
76
    {
77
        return $this->doubleEncode;
78
    }
79
80
    /**
81
     * Returns the encoding used
82
     *
83
     * @return string
84
     */
85
    public function getEncoding(): string
86
    {
87
        return $this->encoding;
88
    }
89
90
    /**
91
     * Get the htmlspecialchars flags
92
     *
93
     * @return int
94
     */
95
    public function getFlags(): int
96
    {
97
        return $this->flags;
98
    }
99
100
    /**
101
     * Escapes HTML
102
     *
103
     * @param mixed $input
104
     *
105
     * @return string
106
     */
107 11
    public function html($input): string
108
    {
109 11
        return htmlspecialchars(
110 11
            $input,
111 11
            $this->flags,
112 11
            $this->encoding,
113 11
            $this->doubleEncode
114
        );
115
    }
116
117
    /**
118
     * Escape JS
119
     *
120
     * @param string $input
121
     *
122
     * @return string
123
     */
124
    public function js(string $input): string
125
    {
126
        return $input;
127
    }
128
129
    /**
130
     * Sets whether we will used double encoding or not
131
     *
132
     * @param bool $flag
133
     *
134
     * @return Escaper
135
     */
136
    public function setDoubleEncode(bool $flag): Escaper
137
    {
138
        $this->doubleEncode = $flag;
139
140
        return $this;
141
    }
142
143
    /**
144
     * Sets the encoding to be used
145
     *
146
     * @param string $encoding
147
     *
148
     * @return Escaper
149
     */
150
    public function setEncoding(string $encoding): Escaper
151
    {
152
        $this->encoding = $encoding;
153
154
        return $this;
155
    }
156
157
    /**
158
     * Escapes a URL
159
     *
160
     * @param string $url
161
     *
162
     * @return string
163
     */
164
    public function url(string $url): string
165
    {
166
        return rawurldecode($url);
167
    }
168
}
169