Skip to content

Commit ac46a06

Browse files
committed
up: add '\' for a global functions
1 parent 36c4649 commit ac46a06

9 files changed

+119
-115
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ e.g
4646
## 项目地址
4747

4848
- **github** https://github.com/inhere/php-validate.git
49-
- **git@osc** https://gitee.com/inhere/php-validate.git
49+
- **gitee** https://gitee.com/inhere/php-validate.git
5050

5151
**注意:**
5252

src/AbstractValidation.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ abstract class AbstractValidation implements ValidationInterface
4040
* @throws \InvalidArgumentException
4141
* @throws \RuntimeException
4242
*/
43-
public function __construct(array $data = [], array $rules = [], array $translates = [], $scene = '', $startValidate = false)
44-
{
43+
public function __construct(
44+
array $data = [],
45+
array $rules = [],
46+
array $translates = [],
47+
string $scene = '',
48+
$startValidate = false
49+
) {
4550
$this->data = $data;
4651
$this
4752
->atScene($scene)
@@ -63,13 +68,18 @@ public function __construct(array $data = [], array $rules = [], array $translat
6368
* @throws \InvalidArgumentException
6469
* @throws \RuntimeException
6570
*/
66-
public static function make(array $data, array $rules = [], array $translates = [], $scene = '', $startValidate = false)
67-
{
71+
public static function make(
72+
array $data,
73+
array $rules = [],
74+
array $translates = [],
75+
string $scene = '',
76+
$startValidate = false
77+
) {
6878
return new static($data, $rules, $translates, $scene, $startValidate);
6979
}
7080

7181
/**
72-
* 创建并且立即开始验证
82+
* Create and start verification immediately
7383
* @param array $data
7484
* @param array $rules
7585
* @param array $translates
@@ -78,13 +88,13 @@ public static function make(array $data, array $rules = [], array $translates =
7888
* @throws \InvalidArgumentException
7989
* @throws \RuntimeException
8090
*/
81-
public static function makeAndValidate(array $data, array $rules = [], array $translates = [], $scene = '')
91+
public static function makeAndValidate(array $data, array $rules = [], array $translates = [], string $scene = '')
8292
{
8393
return new static($data, $rules, $translates, $scene, true);
8494
}
8595

8696
/**
87-
* 创建并且立即开始验证
97+
* Create and start verification immediately
8898
* @param array $data
8999
* @param array $rules
90100
* @param array $translates
@@ -93,7 +103,7 @@ public static function makeAndValidate(array $data, array $rules = [], array $tr
93103
* @throws \InvalidArgumentException
94104
* @throws \RuntimeException
95105
*/
96-
public static function check(array $data, array $rules = [], array $translates = [], $scene = '')
106+
public static function check(array $data, array $rules = [], array $translates = [], string $scene = '')
97107
{
98108
return new static($data, $rules, $translates, $scene, true);
99109
}

src/FieldValidation.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@
2121
*/
2222
class FieldValidation extends AbstractValidation
2323
{
24-
/**
25-
* @return array
26-
*/
27-
// public function rules()
28-
// {
29-
// return [
30-
// ['field', 'required|string:5,10|...', ...],
31-
// ['field0', ['required', 'string:5,10'], ...],
32-
// ['field1', 'rule1|rule2|...', ...],
33-
// ['field2', 'rule1|rule3|...', ...],
34-
// ];
35-
// }
24+
/*
25+
public function rules()
26+
{
27+
return [
28+
['field', 'required|string:5,10|...', ...],
29+
['field0', ['required', 'string:5,10'], ...],
30+
['field1', 'rule1|rule2|...', ...],
31+
['field2', 'rule1|rule3|...', ...],
32+
];
33+
}
34+
*/
3635

3736
/**
3837
* @return \Generator
@@ -95,37 +94,37 @@ protected function collectRules()
9594
*/
9695
protected function parseRule(string $rule, array $row): array
9796
{
98-
$rule = trim($rule, ': ');
97+
$rule = \trim($rule, ': ');
9998

10099
if (false === \strpos($rule, ':')) {
101100
$row[0] = $rule;
102101
return $row;
103102
}
104103

105104
list($name, $args) = \explode(':', $rule, 2);
106-
$args = trim($args, ', ');
105+
$args = \trim($args, ', ');
107106
$row[0] = $name;
108107

109108
switch ($name) {
110109
case 'in':
111110
case 'enum':
112111
case 'ontIn':
113-
$row[] = \array_map('trim', explode(',', $args));
112+
$row[] = \array_map('trim', \explode(',', $args));
114113
break;
115114

116115
case 'size':
117116
case 'range':
118117
case 'string':
119118
case 'between':
120-
if (strpos($args, ',')) {
121-
list($row['min'], $row['max']) = \array_map('trim', explode(',', $args, 2));
119+
if (\strpos($args, ',')) {
120+
list($row['min'], $row['max']) = \array_map('trim', \explode(',', $args, 2));
122121
} else {
123122
$row['min'] = $args;
124123
}
125124
break;
126125
default:
127-
$args = strpos($args, ',') ? \array_map('trim', explode(',', $args)) : [$args];
128-
$row = array_merge($row, $args);
126+
$args = \strpos($args, ',') ? \array_map('trim', \explode(',', $args)) : [$args];
127+
$row = \array_merge($row, $args);
129128
break;
130129
}
131130

src/Utils/DataFiltersTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ protected function callStringCallback($filter, ...$args)
8282
$value = $callback(...$args);
8383

8484
// if $filter is a custom method of the subclass.
85-
} elseif (method_exists($this, $filter . 'Filter')) {
85+
} elseif (\method_exists($this, $filter . 'Filter')) {
8686
$filter .= 'Filter';
8787
$value = $this->$filter(...$args);
8888

8989
// $filter is a method of the class 'FilterList'
90-
} elseif (method_exists(Filters::class, $filter)) {
90+
} elseif (\method_exists(Filters::class, $filter)) {
9191
$value = Filters::$filter(...$args);
9292

9393
// it is function name

src/Utils/Helper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ class Helper
4343

4444
/**
4545
* @param string $ext
46-
* @return mixed|null
46+
* @return string
4747
*/
48-
public static function getImageMime(string $ext)
48+
public static function getImageMime(string $ext): string
4949
{
50-
return self::$imgMimeTypes[$ext] ?? null;
50+
return self::$imgMimeTypes[$ext] ?? '';
5151
}
5252

5353
/**
@@ -301,7 +301,7 @@ public static function call($cb, ...$args)
301301
}
302302

303303
// ClassName/Service::method
304-
$cb = explode('::', $cb, 2);
304+
$cb = \explode('::', $cb, 2);
305305
} elseif (\is_object($cb) && \method_exists($cb, '__invoke')) {
306306
return $cb(...$args);
307307
}

src/Utils/UserAndContextValidatorsTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static function clearValidators()
116116
*/
117117
public static function setValidators(array $validators)
118118
{
119-
self::$_validators = array_merge(self::$_validators, $validators);
119+
self::$_validators = \array_merge(self::$_validators, $validators);
120120
}
121121

122122
/**
@@ -305,7 +305,7 @@ public function fileValidator(string $field, $suffixes = null): bool
305305
return true;
306306
}
307307

308-
$suffix = trim(\strrchr($file['name'], '.'), '.');
308+
$suffix = \trim(\strrchr($file['name'], '.'), '.');
309309

310310
if (!$suffix) {
311311
return false;
@@ -540,7 +540,7 @@ public function intervalDayValidator($val, string $compareField, int $expected,
540540
*/
541541
public static function isCheckFile(string $name): bool
542542
{
543-
return false !== strpos(self::$_fileValidators, '|' . $name . '|');
543+
return false !== \strpos(self::$_fileValidators, '|' . $name . '|');
544544
}
545545

546546
/**
@@ -549,7 +549,7 @@ public static function isCheckFile(string $name): bool
549549
*/
550550
public static function isCheckRequired(string $name): bool
551551
{
552-
return 0 === strpos($name, 'required');
552+
return 0 === \strpos($name, 'required');
553553
}
554554

555555
/**

src/Validation.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ class Validation extends AbstractValidation
2727
/**
2828
* @return array
2929
*/
30-
// public function rules()
31-
// {
32-
// return [
33-
// ['fields', 'validator', arg0, arg1, something ...]
34-
// ['tagId,userId,name,email,freeTime', 'required'],
35-
// ['userId', 'number'],
36-
// ];
37-
// }
30+
/*
31+
public function rules()
32+
{
33+
return [
34+
['fields', 'validator', arg0, arg1, something ...]
35+
['tagId,userId,name,email,freeTime', 'required'],
36+
['userId', 'number'],
37+
];
38+
}
39+
*/
3840

3941
/**
4042
* @param string $key

0 commit comments

Comments
 (0)