Completed
Pull Request — develop_3.0 (#565)
by Hura
06:52
created

ODS::escape()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Box\Spout\Common\Helper\Escaper;
4
5
/**
6
 * Class ODS
7
 * Provides functions to escape and unescape data for ODS files
8
 */
9
class ODS implements EscaperInterface
10
{
11
    /**
12
     * Escapes the given string to make it compatible with ODS
13
     *
14
     * @param string $string The string to escape
15
     * @return string The escaped string
16
     */
17 41
    public function escape($string)
18
    {
19
        // 'ENT_DISALLOWED' ensures that invalid characters in the given document type are replaced.
20
        // Otherwise control characters like a vertical tab "\v" will make the XML document unreadable
21
        // by the XML processor
22
        // @link https://github.com/box/spout/issues/329
23 41
        return htmlspecialchars($string, ENT_NOQUOTES | ENT_DISALLOWED);
24
    }
25
26
    /**
27
     * Unescapes the given string to make it compatible with ODS
28
     *
29
     * @param string $string The string to unescape
30
     * @return string The unescaped string
31
     */
32 29
    public function unescape($string)
33
    {
34
        // ==============
35
        // =   WARNING  =
36
        // ==============
37
        // It is assumed that the given string has already had its XML entities decoded.
38
        // This is true if the string is coming from a DOMNode (as DOMNode already decode XML entities on creation).
39
        // Therefore there is no need to call "htmlspecialchars_decode()".
40 29
        return $string;
41
    }
42
}
43