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
Branch dev (8e16b9)
by t
03:51
created

BlackList::del()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 11
ccs 0
cts 11
cp 0
crap 20
rs 10
1
<?php
2
/**
3
 * Class BlackList
4
 * @link https://www.icy2003.com/
5
 * @author icy2003 <[email protected]>
6
 * @copyright Copyright (c) 2017, icy2003
7
 */
8
namespace icy2003\php\ihelpers;
9
10
/**
11
 * 敏感词过滤
12
 */
13
class BlackList
14
{
15
16
    /**
17
     * 敏感词树
18
     *
19
     * @var array
20
     */
21
    protected $_map = [];
22
23
    /**
24
     * 添加一个敏感词
25
     *
26
     * @param string|array $content
27
     *
28
     * @return static
29
     */
30
    public function add($content)
31
    {
32
        $words = Strings::split($content);
0 ignored issues
show
Bug introduced by
It seems like $content can also be of type array; however, parameter $string of icy2003\php\ihelpers\Strings::split() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
        $words = Strings::split(/** @scrutinizer ignore-type */ $content);
Loading history...
33
        $temp = &$this->_map;
34
        foreach ($words as $word) {
35
            if (false === isset($temp[$word])) {
36
                $temp[$word] = [];
37
            }
38
            $temp = &$temp[$word];
39
        }
40
        $temp['isFind'] = true;
41
        return $this;
42
    }
43
44
    /**
45
     * 删除一个敏感词
46
     *
47
     * @param string|array $content
48
     *
49
     * @return static
50
     */
51
    public function del($content)
52
    {
53
        $words = is_string($content) ? Strings::split($content) : $content;
54
        $temp = &$this->_map;
55
        foreach ($words as $word) {
56
            if (isset($temp[$word])) {
57
                $temp = &$temp[$word];
58
            }
59
        }
60
        $temp['isFind'] = false;
61
        return $this;
62
    }
63
64
    /**
65
     * 从头开始检测一个字符串是否是敏感词
66
     *
67
     * - 发现敏感词,则返回该词
68
     * - 没有敏感词,则返回 false
69
     *
70
     * @param string|array $content
71
     * @param boolean $findMore
72
     *
73
     * @return string|boolean
74
     */
75
    protected function _isStart($content, $findMore = true)
76
    {
77
        $words = is_string($content) ? Strings::split($content) : $content;
78
        $temp = &$this->_map;
79
        $string = '';
80
        $isFind = false;
81
        foreach ($words as $word) {
82
            if (isset($temp[$word])) {
83
                $string .= $word;
84
                if (true === I::get($temp[$word], 'isFind')) {
85
                    $isFind = true;
86
                    if (true === $findMore) {
87
                        $temp = &$temp[$word];
88
                        continue;
89
                    } else {
90
                        return $string;
91
                    }
92
                } else {
93
                    $isFind = false;
94
                    $temp = &$temp[$word];
95
                    continue;
96
                }
97
            }
98
            return true === $isFind ? $string : false;
99
        }
100
    }
101
102
    /**
103
     * 查找一段文本里所有敏感词
104
     *
105
     * @param string|array $content
106
     *
107
     * @return array
108
     */
109
    public function find($content)
110
    {
111
        $words = is_string($content) ? Strings::split($content) : $content;
112
        $strings = [];
113
        while (true) {
114
            if (empty($words)) {
115
                return $strings;
116
            }
117
            $string = $this->_isStart($words);
118
            if (is_string($string)) {
119
                $strings[] = $string;
120
            }
121
            array_shift($words);
122
        }
123
    }
124
125
    /**
126
     * 返回替换敏感词后的文本
127
     *
128
     * @param string|array $content
129
     * @param string $char
130
     *
131
     * @return string
132
     */
133
    public function replace($content, $char = '*')
134
    {
135
        $words = $this->find($content);
136
        $content = implode('', $words);
137
        $array = [];
138
        foreach ($words as $word) {
139
            $array[$word] = Strings::repeat($char, Strings::length($word));
140
        }
141
        return Strings::replace($content, $array);
142
    }
143
144
    /**
145
     * 返回敏感词树
146
     *
147
     * @return array
148
     */
149
    public function toArray()
150
    {
151
        return $this->_map;
152
    }
153
154
    /**
155
     * 导出敏感词树到 php 文件
156
     *
157
     * @param string|null $file
158
     *
159
     * @return void
160
     */
161
    public function toPhp($file = null)
162
    {
163
        null === $file && $file = __DIR__ . '/' . date('YmdHis') . '.php';
164
        $local = new LocalFile();
0 ignored issues
show
Bug introduced by
The type icy2003\php\ihelpers\LocalFile was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
165
        $array = Arrays::export($this->toArray(), true);
166
        $local->putFileContent($file, <<<EOT
167
<?php
168
169
return {$array};
170
171
EOT);
172
    }
173
}
174