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

ODS   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 34
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A escape() 0 8 1
A unescape() 0 10 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