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 ( d91c4a...ff776f )
by Zordius
02:25
created

Token::setDelimiter()   B

Complexity

Conditions 6
Paths 20

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 21
ccs 16
cts 16
cp 1
rs 8.7624
cc 6
eloc 15
nc 20
nop 3
crap 6
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 handle LightnCandy token
16
 *
17
 * @package    LightnCandy
18
 * @author     Zordius <[email protected]>
19
 */
20
21
namespace LightnCandy;
22
23
/**
24
 * LightnCandy Token handler
25
 */
26
class Token
27
{
28
    // RegExps
29
    const VARNAME_SEARCH = '/(\\[[^\\]]+\\]|[^\\[\\]\\.]+)/';
30
31
    // Positions of matched token
32
    const POS_LOTHER = 1;
33
    const POS_LSPACE = 2;
34
    const POS_BEGINTAG = 3;
35
    const POS_LSPACECTL = 4;
36
    const POS_BEGINRAW = 5;
37
    const POS_OP = 6;
38
    const POS_INNERTAG = 7;
39
    const POS_ENDRAW = 8;
40
    const POS_RSPACECTL = 9;
41
    const POS_ENDTAG = 10;
42
    const POS_RSPACE = 11;
43
    const POS_ROTHER = 12;
44
45
    /**
46
     * Setup delimiter by default or provided string
47
     *
48
     * @param array<string,array|string|integer> $context Current context
49
     * @param string $left left string of a token
0 ignored issues
show
Documentation introduced by
Should the type for parameter $left not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
50
     * @param string $right right string of a token
0 ignored issues
show
Documentation introduced by
Should the type for parameter $right not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
51
     */
52 716
    public static function setDelimiter(&$context, $left = null, $right = null) {
53 716
        if (!$left) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $left of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
54 716
            $left = $context['delimiters'][0];
55
        }
56 716
        if (!$right) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $right of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
57 716
            $right = $context['delimiters'][1];
58
        }
59 716
        if (preg_match('/=/', "$left$right")) {
60 1
            $context['error'][] = "Can not set delimiter contains '=' , you try to set delimiter as '$left' and '$right'.";
61 1
            return;
62
        }
63
64 716
        $context['tokens']['startchar'] = substr($left, 0, 1);
65 716
        $context['tokens']['left'] = $left;
66 716
        $context['tokens']['right'] = $right;
67 716
        $rawcount = $context['rawblock'] ? '{2}' : ($context['flags']['rawblock'] ? '{0,2}' : '?');
68 716
        $left = preg_quote($left);
69 716
        $right = preg_quote($right);
70
71 716
        $context['tokens']['search'] = "/^(.*?)(\\s*)($left)(~?)(\\{{$rawcount})([\\^#\\/!&>\\*]{0,2})(.*?)(\\}{$rawcount})(~?)($right)(\\s*)(.*)\$/s";
72 716
    }
73
74
    /**
75
     * return token string
76
     *
77
     * @param string[] $token detected handlebars {{ }} token
78
     * @param string[]|null $merge list of token strings to be merged
79
     *
80
     * @return string Return whole token
81
     *
82
     * @expect 'c' when input array(0, 'a', 'b', 'c', 'd', 'e')
83
     * @expect 'cd' when input array(0, 'a', 'b', 'c', 'd', 'e', 'f')
84
     * @expect 'qd' when input array(0, 'a', 'b', 'c', 'd', 'e', 'f'), array(3 => 'q')
85
     */
86 675
    public static function toString($token, $merge = null) {
87 675
        if (is_array($merge)) {
88 12
            $token = array_replace($token, $merge);
89
        }
90 675
        return implode('', array_slice($token, 3, -2));
91
    }
92
}
93
94