GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SafeString   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 63
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 4 1
A __construct() 0 4 3
A stripExtendedComments() 0 4 1
A escapeTemplate() 0 4 1
1
<?php
2
/*
3
4
MIT License
5
Copyright 2013-2020 Zordius Chen. All Rights Reserved.
6
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
10
Origin: https://github.com/zordius/lightncandy
11
*/
12
13
/**
14
 * file to keep LightnCandy string utilities
15
 *
16
 * @package    LightnCandy
17
 * @author     Zordius <[email protected]>
18
 */
19
20
namespace LightnCandy;
21
22
/**
23
 * LightnCandy SafeString class
24
 */
25
class SafeString extends Encoder
26
{
27
    const EXTENDED_COMMENT_SEARCH = '/{{!--.*?--}}/s';
28
    const IS_SUBEXP_SEARCH = '/^\(.+\)$/s';
29
    const IS_BLOCKPARAM_SEARCH = '/^ +\|(.+)\|$/s';
30
31
    private $string;
32
33
    public static $jsContext = array(
34
        'flags' => array(
35
            'jstrue' => 1,
36
            'jsobj' => 1,
37
        )
38
    );
39
40
    /**
41
     * Constructor
42
     *
43
     * @param string $str input string
44
     * @param bool|string $escape false to not escape, true to escape, 'encq' to escape as handlebars.js
45
     */
46 4
    public function __construct($str, $escape = false)
47
    {
48 4
        $this->string = $escape ? (($escape === 'encq') ? static::encq(static::$jsContext, $str) : static::enc(static::$jsContext, $str)) : $str;
49 4
    }
50
51 4
    public function __toString()
52
    {
53 4
        return $this->string;
54
    }
55
56
    /**
57
     * Strip extended comments {{!-- .... --}}
58
     *
59
     * @param string $template handlebars template string
60
     *
61
     * @return string Stripped template
62
     *
63
     * @expect 'abc' when input 'abc'
64
     * @expect 'abc{{!}}cde' when input 'abc{{!}}cde'
65
     * @expect 'abc{{! }}cde' when input 'abc{{!----}}cde'
66
     */
67 796
    public static function stripExtendedComments($template)
68
    {
69 796
        return preg_replace(static::EXTENDED_COMMENT_SEARCH, '{{! }}', $template);
70
    }
71
72
    /**
73
     * Escape template
74
     *
75
     * @param string $template handlebars template string
76
     *
77
     * @return string Escaped template
78
     *
79
     * @expect 'abc' when input 'abc'
80
     * @expect 'a\\\\bc' when input 'a\bc'
81
     * @expect 'a\\\'bc' when input 'a\'bc'
82
     */
83 796
    public static function escapeTemplate($template)
84
    {
85 796
        return addcslashes(addcslashes($template, '\\'), "'");
86
    }
87
}
88