Completed
Push — master ( 7a6aee...e5c914 )
by Colin
52:42 queued 27:44
created

Xml   A

Coupling/Cohesion

Components 0
Dependencies 0

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A escape() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 *
8
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
9
 *  - (c) John MacFarlane
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace League\CommonMark\Util;
16
17
/**
18
 * Utility class for handling/generating XML and HTML
19
 */
20
final class Xml
21
{
22
    /**
23
     * @param string $string
24
     * @param bool   $preserveEntities
25
     *
26
     * @return string
27
     */
28
    public static function escape($string, $preserveEntities = false)
29
    {
30
        if ($preserveEntities) {
31
            $string = preg_replace('/[&](?![#](x[a-f0-9]{1,8}|[0-9]{1,8});|[a-z][a-z0-9]{1,31};)/i', '&amp;', $string);
32
        } else {
33
            $string = str_replace('&', '&amp;', $string);
34
        }
35
36
        return str_replace(['<', '>', '"'], ['&lt;', '&gt;', '&quot;'], $string);
37
    }
38
}
39