Skip to content

Commit 737de2f

Browse files
committed
run code inspection check. fix some errors
1 parent e967e90 commit 737de2f

34 files changed

+297
-354
lines changed

libs/arr-utils/src/ArrayHelper.php

+16-26
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,15 @@ public static function existsAll($need, $arr, $type = false)
311311
self::existsAll($v, $arr, $type);
312312
}
313313

314+
} elseif (\strpos($need, ',') !== false) {
315+
$need = \explode(',', $need);
316+
self::existsAll($need, $arr, $type);
314317
} else {
318+
$arr = self::valueToLower($arr);//小写
319+
$need = \strtolower(trim($need));//小写
315320

316-
#以逗号分隔的会被拆开,组成数组
317-
if (\strpos($need, ',') !== false) {
318-
$need = \explode(',', $need);
319-
self::existsAll($need, $arr, $type);
320-
} else {
321-
$arr = self::valueToLower($arr);//小写
322-
$need = \strtolower(trim($need));//小写
323-
324-
if (!\in_array($need, $arr, $type)) {
325-
return $need;
326-
}
321+
if (!\in_array($need, $arr, $type)) {
322+
return $need;
327323
}
328324
}
329325

@@ -898,17 +894,13 @@ public static function toString(
898894
if (\is_array($value)) {
899895
$string .= $keyStr . 'Array(' . self::toString($value, $length, $cycles, $showKey, $addMark, $separator,
900896
$string) . ')' . $separator;
897+
} elseif (\is_object($value)) {
898+
$string .= $keyStr . 'Object(' . \get_class($value) . ')' . $separator;
899+
} elseif (\is_resource($value)) {
900+
$string .= $keyStr . 'Resource(' . get_resource_type($value) . ')' . $separator;
901901
} else {
902-
if (\is_object($value)) {
903-
$string .= $keyStr . 'Object(' . \get_class($value) . ')' . $separator;
904-
} else {
905-
if (\is_resource($value)) {
906-
$string .= $keyStr . 'Resource(' . get_resource_type($value) . ')' . $separator;
907-
} else {
908-
$value = \strlen($value) > 150 ? substr($value, 0, 150) : $value;
909-
$string .= $mark . $keyStr . trim(htmlspecialchars($value)) . $mark . $separator;
910-
}
911-
}
902+
$value = \strlen($value) > 150 ? substr($value, 0, 150) : $value;
903+
$string .= $mark . $keyStr . trim(htmlspecialchars($value)) . $mark . $separator;
912904
}
913905
}
914906

@@ -963,12 +955,10 @@ public static function toLimitOut($array): array
963955

964956
if (\is_array($value) || \is_object($value)) {
965957
$value = \gettype($value) . '(...)';
958+
} elseif (\is_string($value) || is_numeric($value)) {
959+
$value = \strlen(trim($value));
966960
} else {
967-
if (\is_string($value) || is_numeric($value)) {
968-
$value = \strlen(trim($value));
969-
} else {
970-
$value = \gettype($value) . "($value)";
971-
}
961+
$value = \gettype($value) . "($value)";
972962
}
973963

974964
$array[$key] = $value;

libs/cli-utils/src/Cli.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public static function parseArgv(array $noValues = [], $mergeOpts = false): arra
200200
$value = true;
201201

202202
// long-opt: (--<opt>)
203-
if ($opt{0} === '-') {
203+
if (\strpos($opt, '-') === 0) {
204204
$isLong = true;
205205
$opt = substr($opt, 1);
206206

@@ -238,14 +238,11 @@ public static function parseArgv(array $noValues = [], $mergeOpts = false): arra
238238
}
239239

240240
// arguments: param doesn't belong to any option, define it is args
241+
} elseif (strpos($p, '=') !== false) { // value specified inline (<arg>=<value>)
242+
list($name, $value) = explode('=', $p, 2);
243+
$args[$name] = $value;
241244
} else {
242-
// value specified inline (<arg>=<value>)
243-
if (strpos($p, '=') !== false) {
244-
list($name, $value) = explode('=', $p, 2);
245-
$args[$name] = $value;
246-
} else {
247-
$args[] = $p;
248-
}
245+
$args[] = $p;
249246
}
250247
}
251248

libs/cli-utils/src/Color.php

+44-44
Original file line numberDiff line numberDiff line change
@@ -34,63 +34,63 @@
3434
*/
3535
class Color
3636
{
37-
const NORMAL = 0;
37+
public const NORMAL = 0;
3838

3939
// Foreground color
40-
const FG_BLACK = 30;
41-
const FG_RED = 31;
42-
const FG_GREEN = 32;
43-
const FG_BROWN = 33; // like yellow
44-
const FG_BLUE = 34;
45-
const FG_CYAN = 36;
46-
const FG_WHITE = 37;
47-
const FG_DEFAULT = 39;
40+
public const FG_BLACK = 30;
41+
public const FG_RED = 31;
42+
public const FG_GREEN = 32;
43+
public const FG_BROWN = 33; // like yellow
44+
public const FG_BLUE = 34;
45+
public const FG_CYAN = 36;
46+
public const FG_WHITE = 37;
47+
public const FG_DEFAULT = 39;
4848

4949
// extra Foreground color
50-
const FG_DARK_GRAY = 90;
51-
const FG_LIGHT_RED = 91;
52-
const FG_LIGHT_GREEN = 92;
53-
const FG_LIGHT_YELLOW = 93;
54-
const FG_LIGHT_BLUE = 94;
55-
const FG_LIGHT_MAGENTA = 95;
56-
const FG_LIGHT_CYAN = 96;
57-
const FG_WHITE_W = 97;
50+
public const FG_DARK_GRAY = 90;
51+
public const FG_LIGHT_RED = 91;
52+
public const FG_LIGHT_GREEN = 92;
53+
public const FG_LIGHT_YELLOW = 93;
54+
public const FG_LIGHT_BLUE = 94;
55+
public const FG_LIGHT_MAGENTA = 95;
56+
public const FG_LIGHT_CYAN = 96;
57+
public const FG_WHITE_W = 97;
5858

5959
// Background color
60-
const BG_BLACK = 40;
61-
const BG_RED = 41;
62-
const BG_GREEN = 42;
63-
const BG_BROWN = 43; // like yellow
64-
const BG_BLUE = 44;
65-
const BG_CYAN = 46;
66-
const BG_WHITE = 47;
67-
const BG_DEFAULT = 49;
60+
public const BG_BLACK = 40;
61+
public const BG_RED = 41;
62+
public const BG_GREEN = 42;
63+
public const BG_BROWN = 43; // like yellow
64+
public const BG_BLUE = 44;
65+
public const BG_CYAN = 46;
66+
public const BG_WHITE = 47;
67+
public const BG_DEFAULT = 49;
6868

6969
// extra Background color
70-
const BG_DARK_GRAY = 100;
71-
const BG_LIGHT_RED = 101;
72-
const BG_LIGHT_GREEN = 102;
73-
const BG_LIGHT_YELLOW = 103;
74-
const BG_LIGHT_BLUE = 104;
75-
const BG_LIGHT_MAGENTA = 105;
76-
const BG_LIGHT_CYAN = 106;
77-
const BG_WHITE_W = 107;
70+
public const BG_DARK_GRAY = 100;
71+
public const BG_LIGHT_RED = 101;
72+
public const BG_LIGHT_GREEN = 102;
73+
public const BG_LIGHT_YELLOW = 103;
74+
public const BG_LIGHT_BLUE = 104;
75+
public const BG_LIGHT_MAGENTA = 105;
76+
public const BG_LIGHT_CYAN = 106;
77+
public const BG_WHITE_W = 107;
7878

7979
// color option
80-
const BOLD = 1; // 加粗
81-
const FUZZY = 2; // 模糊(不是所有的终端仿真器都支持)
82-
const ITALIC = 3; // 斜体(不是所有的终端仿真器都支持)
83-
const UNDERSCORE = 4; // 下划线
84-
const BLINK = 5; // 闪烁
85-
const REVERSE = 7; // 颠倒的 交换背景色与前景色
86-
const CONCEALED = 8; // 隐匿的
80+
public const BOLD = 1; // 加粗
81+
public const FUZZY = 2; // 模糊(不是所有的终端仿真器都支持)
82+
public const ITALIC = 3; // 斜体(不是所有的终端仿真器都支持)
83+
public const UNDERSCORE = 4; // 下划线
84+
public const BLINK = 5; // 闪烁
85+
public const REVERSE = 7; // 颠倒的 交换背景色与前景色
86+
public const CONCEALED = 8; // 隐匿的
8787

8888
/**
8989
* some styles
9090
* custom style: fg;bg;opt
9191
* @var array
9292
*/
93-
const STYLES = [
93+
public const STYLES = [
9494
// basic
9595
'red' => '0;31',
9696
'blue' => '0;34',
@@ -156,17 +156,17 @@ class Color
156156
/**
157157
* Regex to match tags
158158
*/
159-
const COLOR_TAG = '/<([a-z=;]+)>(.*?)<\/\\1>/s';
159+
public const COLOR_TAG = '/<([a-z=;]+)>(.*?)<\/\\1>/s';
160160

161161
/**
162162
* Regex used for removing color codes
163163
*/
164-
const STRIP_TAG = '/<[\/]?[a-zA-Z=;]+>/';
164+
public const STRIP_TAG = '/<[\/]?[a-zA-Z=;]+>/';
165165

166166
/**
167167
* CLI color template
168168
*/
169-
const COLOR_TPL = "\033[%sm%s\033[0m";
169+
public const COLOR_TPL = "\033[%sm%s\033[0m";
170170

171171
/**
172172
* @param string $method

libs/cli-utils/src/Console.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
class Console extends Cli
1616
{
17-
const LOG_LEVEL2TAG = [
17+
public const LOG_LEVEL2TAG = [
1818
'info' => 'info',
1919
'warn' => 'warning',
2020
'warning' => 'warning',
@@ -45,7 +45,7 @@ public static function log(string $msg, array $data = [], string $type = 'info',
4545
$userOpts = [];
4646

4747
foreach ($opts as $n => $v) {
48-
if (\is_numeric($n) || $n[0] === '_') {
48+
if (\is_numeric($n) || \strpos($n, '_') === 0) {
4949
$userOpts[] = "[$v]";
5050
} else {
5151
$userOpts[] = "[$n:$v]";

libs/cli-utils/src/Download.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
*/
1515
final class Download
1616
{
17-
const PROGRESS_TEXT = 'text';
18-
const PROGRESS_BAR = 'bar';
17+
public const PROGRESS_TEXT = 'text';
18+
public const PROGRESS_BAR = 'bar';
1919

2020
/** @var int */
2121
private $fileSize;

libs/cli-utils/src/Highlighter.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
*/
1717
class Highlighter
1818
{
19-
const TOKEN_DEFAULT = 'token_default';
20-
const TOKEN_COMMENT = 'token_comment';
21-
const TOKEN_STRING = 'token_string';
22-
const TOKEN_HTML = 'token_html';
23-
const TOKEN_KEYWORD = 'token_keyword';
24-
25-
const ACTUAL_LINE_MARK = 'actual_line_mark';
26-
const LINE_NUMBER = 'line_number';
19+
public const TOKEN_DEFAULT = 'token_default';
20+
public const TOKEN_COMMENT = 'token_comment';
21+
public const TOKEN_STRING = 'token_string';
22+
public const TOKEN_HTML = 'token_html';
23+
public const TOKEN_KEYWORD = 'token_keyword';
24+
25+
public const ACTUAL_LINE_MARK = 'actual_line_mark';
26+
public const LINE_NUMBER = 'line_number';
2727

2828
// @var Style
2929
//private $color;

libs/cli-utils/src/Terminal.php

+21-21
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@
1818
*/
1919
final class Terminal
2020
{
21-
const BEGIN_CHAR = "\033[";
22-
const END_CHAR = "\033[0m";
21+
public const BEGIN_CHAR = "\033[";
22+
public const END_CHAR = "\033[0m";
2323

2424
// Control cursor code name list. more @see [[self::$ctrlCursorCodes]]
25-
const CUR_HIDE = 'hide';
26-
const CUR_SHOW = 'show';
27-
const CUR_SAVE_POSITION = 'savePosition';
28-
const CUR_RESTORE_POSITION = 'restorePosition';
29-
const CUR_UP = 'up';
30-
const CUR_DOWN = 'down';
31-
const CUR_FORWARD = 'forward';
32-
const CUR_BACKWARD = 'backward';
33-
const CUR_NEXT_LINE = 'nextLine';
34-
const CUR_PREV_LINE = 'prevLine';
35-
const CUR_COORDINATE = 'coordinate';
25+
public const CUR_HIDE = 'hide';
26+
public const CUR_SHOW = 'show';
27+
public const CUR_SAVE_POSITION = 'savePosition';
28+
public const CUR_RESTORE_POSITION = 'restorePosition';
29+
public const CUR_UP = 'up';
30+
public const CUR_DOWN = 'down';
31+
public const CUR_FORWARD = 'forward';
32+
public const CUR_BACKWARD = 'backward';
33+
public const CUR_NEXT_LINE = 'nextLine';
34+
public const CUR_PREV_LINE = 'prevLine';
35+
public const CUR_COORDINATE = 'coordinate';
3636

3737
// Control screen code name list. more @see [[self::$ctrlScreenCodes]]
38-
const CLEAR = 'clear';
39-
const CLEAR_BEFORE_CURSOR = 'clearBeforeCursor';
40-
const CLEAR_LINE = 'clearLine';
41-
const CLEAR_LINE_BEFORE_CURSOR = 'clearLineBeforeCursor';
42-
const CLEAR_LINE_AFTER_CURSOR = 'clearLineAfterCursor';
43-
44-
const SCROLL_UP = 'scrollUp';
45-
const SCROLL_DOWN = 'scrollDown';
38+
public const CLEAR = 'clear';
39+
public const CLEAR_BEFORE_CURSOR = 'clearBeforeCursor';
40+
public const CLEAR_LINE = 'clearLine';
41+
public const CLEAR_LINE_BEFORE_CURSOR = 'clearLineBeforeCursor';
42+
public const CLEAR_LINE_AFTER_CURSOR = 'clearLineAfterCursor';
43+
44+
public const SCROLL_UP = 'scrollUp';
45+
public const SCROLL_DOWN = 'scrollDown';
4646

4747
/**
4848
* current class's instance

libs/collection/src/ActiveData.php

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public function get(string $name)
118118
* Defined by IteratorAggregate interface
119119
* Returns an iterator for this object, for use with foreach
120120
* @return \ArrayIterator
121+
* @throws \ReflectionException
121122
*/
122123
public function getIterator()
123124
{

libs/collection/src/Collection.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ class Collection extends SimpleCollection
6262
*/
6363
protected static $formats = ['json', 'php', 'ini', 'yml'];
6464

65-
const FORMAT_JSON = 'json';
66-
const FORMAT_PHP = 'php';
67-
const FORMAT_INI = 'ini';
68-
const FORMAT_YML = 'yml';
65+
public const FORMAT_JSON = 'json';
66+
public const FORMAT_PHP = 'php';
67+
public const FORMAT_INI = 'ini';
68+
public const FORMAT_YML = 'yml';
6969

7070
/**
7171
* __construct

libs/collection/src/Configuration.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
final class Configuration extends Collection
1818
{
19-
const MODE_DATA = 'data';
20-
const MODE_FOLDER = 'folder';
19+
public const MODE_DATA = 'data';
20+
public const MODE_FOLDER = 'folder';
2121

2222
/**
2323
* config mode

libs/collection/src/Language.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Language implements \ArrayAccess, \Countable, \IteratorAggregate
9494
*/
9595
private $ignoreError = false;
9696

97-
const DEFAULT_FILE_KEY = '__default';
97+
public const DEFAULT_FILE_KEY = '__default';
9898

9999
/**
100100
* @param array $settings

libs/data-parser/test/JsonParserTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public function testDecode()
2424
$parser = new JsonParser();
2525
$ret = $parser->decode($str);
2626

27-
$this->assertInternalType('array', $ret);
2827
$this->assertArrayHasKey('name', $ret);
2928
}
3029

@@ -37,7 +36,6 @@ public function testEncode()
3736
$parser = new JsonParser();
3837
$ret = $parser->encode($data);
3938

40-
$this->assertInternalType('string', $ret);
4139
$this->assertJson($ret);
4240
}
4341
}

0 commit comments

Comments
 (0)