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.

NestedStringCut::stateQ()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
nc 4
nop 3
dl 0
loc 15
ccs 0
cts 13
cp 0
crap 30
rs 9.4555
c 0
b 0
f 0
1
<?php
2
3
namespace PhpBoot\DB;
4
5
/**
6
 * 剪出字符串中的嵌套字符串
7
 * 既从aaa"bb\"b"ccc中, 取出"bb\"b"
8
 * @author caoym
9
 */
10
class NestedStringCut{
11
    
12 2
    public function __construct($str){
13
        
14 2
        $pos = 0;
15 2
        $state = 'stateNormal';
16 2
        while (true){
17 2
            $pos = $this->$state($str, $pos, $state);
18 2
            if($pos === false){
19 2
                break;
20
            }
21
        };
22 2
        return false;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
23
    }
24
    
25
    public function  getSnippets(){
26
        return $this->snippets;
27
    }
28
    
29 2
    public function  getText(){
30 2
        return  implode('', $this->snippets);
31
    }
32
    /**
33
     * 将剪切后的字符串位置转换成原始字符串位置
34
     * @param int $pos 
35
     * @param int
36
     */
37 2
    public function mapPos($pos){
38
       
39 2
        foreach ($this->snippets as $k => $v){
40 2
            $pos += $k;
41 2
            if($pos < $k + strlen($v)){
42 2
                break;
43
            }
44
            $pos -= ($k + strlen($v));
45
            
46 2
        }
47 2
        return $pos;
48
    }
49
    /**
50
     * 普通状态
51
     */
52 2
    private function stateNormal($str, $pos, &$next){
53 2
        $ori = $pos;
54 2
        $posSQ = strpos($str, '\'', $pos);
55 2
        $posDQ = strpos($str, '"', $pos);
56 2
        $pos = $posSQ;
57 2
        $this->subStateQ = '\'';
58 2
        $next = 'stateQ';
59 2
        if($posDQ !== false && (($posDQ < $pos) || ($pos === false)) ){
60
            $pos = $posDQ;
61
            $this->subStateQ = '"';
62
        }
63 2
        if($pos !== false){
64
            $this->snippets[$ori] = substr($str, $ori, $pos-$ori);
65
            $pos ++;
66
        }else{
67 2
            $this->snippets[$ori] = substr($str, $ori);
68
        }
69 2
        return $pos;
70
    }
71
    
72
    /**
73
     * 进入引号状态
74
     */
75
    private function stateQ($str, $pos, &$next){
76
        $posESC = strpos($str, '\\', $pos);
77
        $posQ = strpos($str, $this->subStateQ, $pos);
78
        $pos = $posESC;
79
        $next = 'stateESC';
80
        
81
        if($posQ !== false && (($posQ<$posESC) || ($posESC === false))){
82
            $pos = $posQ;
83
            $next = 'stateNormal';
84
        }
85
        if($pos !== false){
86
            $pos ++;
87
        }
88
        return $pos;
89
    }
90
    /**
91
     * 进入转义状态
92
     */
93
    private function stateESC($str, $pos, &$next){
94
        $pos++;
95
        if($pos >= strlen($str)){
96
            return false;
97
        }
98
        $next = 'stateQ';
99
        return $pos;
100
    }
101
    /**
102
     * 去掉嵌套字符串后的内容
103
     * @var array
104
     */
105
    private $snippets=array();
106
    
107
    private $subStateQ;
108
}
109