Passed
Push — master ( b846a2...3a35da )
by Nikolaos
04:25
created

Escaper::js()   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 1
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
use const ENT_QUOTES;
15
use const ENT_SUBSTITUTE;
16
17
/**
18
 * Class Escaper
19
 *
20
 * @property bool   $doubleEncode
21
 * @property string $encoding
22
 * @property int    $flags
23
 */
24
class Escaper
25
{
26
    /**
27
     * @var bool
28
     */
29
    protected $doubleEncode = true;
30
31
    /**
32
     * @var string
33
     */
34
    protected $encoding = "utf-8";
35
36
    /**
37
     * ENT_QUOTES | ENT_SUBSTITUTE
38
     *
39
     * @var int
40
     */
41
    protected $flags = 11;
42
43
    /**
44
     * Escape HTML attributes
45
     *
46
     * @param string $input
47
     *
48
     * @return string
49
     */
50 20
    public function attributes(string $input): string
51
    {
52 20
        return $input;
53
    }
54
55
    /**
56
     * Escape CSS
57
     *
58
     * @param string $input
59
     *
60
     * @return string
61
     */
62
    public function css(string $input): string
63
    {
64
        return $input;
65
    }
66
67
    /**
68
     * Returns whether we will use double encoding or not
69
     *
70
     * @return bool
71
     */
72
    public function getDoubleEncode(): bool
73
    {
74
        return $this->doubleEncode;
75
    }
76
77
    /**
78
     * Returns the encoding used
79
     *
80
     * @return string
81
     */
82
    public function getEncoding(): string
83
    {
84
        return $this->encoding;
85
    }
86
87
    /**
88
     * Get the htmlspecialchars flags
89
     *
90
     * @return int
91
     */
92
    public function getFlags(): int
93
    {
94
        return $this->flags;
95
    }
96
97
    /**
98
     * Escapes HTML
99
     *
100
     * @param mixed $input
101
     *
102
     * @return string
103
     */
104 11
    public function html($input): string
105
    {
106 11
        return htmlspecialchars(
107 11
            $input,
108 11
            $this->flags,
109 11
            $this->encoding,
110 11
            $this->doubleEncode
111
        );
112
    }
113
114
    /**
115
     * Escape JS
116
     *
117
     * @param string $input
118
     *
119
     * @return string
120
     */
121
    public function js(string $input): string
122
    {
123
        return $input;
124
    }
125
126
    /**
127
     * Sets whether we will used double encoding or not
128
     *
129
     * @param bool $flag
130
     *
131
     * @return Escaper
132
     */
133
    public function setDoubleEncode(bool $flag): Escaper
134
    {
135
        $this->doubleEncode = $flag;
136
137
        return $this;
138
    }
139
140
    /**
141
     * Sets the encoding to be used
142
     *
143
     * @param string $encoding
144
     *
145
     * @return Escaper
146
     */
147
    public function setEncoding(string $encoding): Escaper
148
    {
149
        $this->encoding = $encoding;
150
151
        return $this;
152
    }
153
154
    /**
155
     * Escapes a URL
156
     *
157
     * @param string $url
158
     *
159
     * @return string
160
     */
161
    public function url(string $url): string
162
    {
163
        return rawurldecode($url);
164
    }
165
}
166