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.
Completed
Push — master ( 898ed8...ccf3f3 )
by Zordius
02:20
created

SafeString::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
cc 3
eloc 2
nc 4
nop 2
crap 3
1
<?php
2
/*
3
4
Copyrights for code authored by Yahoo! Inc. is licensed under the following terms:
5
MIT License
6
Copyright (c) 2013-2015 Yahoo! Inc. All Rights Reserved.
7
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:
8
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
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.
10
11
Origin: https://github.com/zordius/lightncandy
12
*/
13
14
/**
15
 * file to keep LightnCandy string utilities
16
 *
17
 * @package    LightnCandy
18
 * @author     Zordius <[email protected]>
19
 */
20
21
namespace LightnCandy;
22
23
use \LightnCandy\Encoder;
24
25
/**
26
 * LightnCandy SafeString class
27
 */
28
class SafeString extends Encoder
29
{
30
    const EXTENDED_COMMENT_SEARCH = '/{{!--.*?--}}/s';
31
    const IS_SUBEXP_SEARCH = '/^\(.+\)$/s';
32
    const IS_BLOCKPARAM_SEARCH = '/^ +\|(.+)\|$/s';
33
34
    private $string;
35
36
    public static $jsContext = array(
37
        'flags' => array(
38
            'jstrue' => 1,
39
            'jsobj' => 1,
40
        )
41
    );
42
43
    /**
44
     * Constructor
45
     *
46
     * @param string $str input string
47
     * @param bool|string $escape false to not escape, true to escape, 'encq' to escape as handlebars.js
48
     *
49
     * @return string Stripped template
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
50
     *
51
     * @expect 'abc' when input 'abc'
52
     * @expect 'abc{{!}}cde' when input 'abc{{!}}cde'
53
     * @expect 'abc{{! }}cde' when input 'abc{{!----}}cde'
54
     */
55 4
    function __construct($str, $escape = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
56 4
        $this->string = $escape ? (($escape === 'encq') ? static::encq(static::$jsContext, $str) : static::enc(static::$jsContext, $str)) : $str;
57 4
    }
58
59 4
    function __toString() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
60 4
        return $this->string;
61
    }
62
63
    /**
64
     * Strip extended comments {{!-- .... --}}
65
     *
66
     * @param string $template handlebars template string
67
     *
68
     * @return string Stripped template
69
     *
70
     * @expect 'abc' when input 'abc'
71
     * @expect 'abc{{!}}cde' when input 'abc{{!}}cde'
72
     * @expect 'abc{{! }}cde' when input 'abc{{!----}}cde'
73
     */
74 718
    public static function stripExtendedComments($template) {
75 718
        return preg_replace(static::EXTENDED_COMMENT_SEARCH, '{{! }}', $template);
76
    }
77
78
    /**
79
     * Escape template
80
     *
81
     * @param string $template handlebars template string
82
     *
83
     * @return string Escaped template
84
     *
85
     * @expect 'abc' when input 'abc'
86
     * @expect 'a\\\\bc' when input 'a\bc'
87
     * @expect 'a\\\'bc' when input 'a\'bc'
88
     */
89 718
    public static function escapeTemplate($template) {
90 718
        return addcslashes(addcslashes($template, '\\'), "'");
91
    }
92
}
93
94