Skip to content

Commit a71416b

Browse files
committed
update: use full import for all functions
1 parent cf3e931 commit a71416b

25 files changed

+586
-383
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"php": ">7.1.0"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "^6.5"
25+
"phpunit/phpunit": "^7.5"
2626
},
2727
"autoload": {
2828
"psr-4": {

src/AbstractValidation.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace Inhere\Validate;
1010

11+
use InvalidArgumentException;
12+
use RuntimeException;
13+
1114
/**
1215
* Class AbstractValidation
1316
* @package Inhere\Validate
@@ -32,8 +35,8 @@ abstract class AbstractValidation implements ValidationInterface
3235
* @param string $scene
3336
* @param bool $startValidate 立即开始验证
3437
*
35-
* @throws \InvalidArgumentException
36-
* @throws \RuntimeException
38+
* @throws InvalidArgumentException
39+
* @throws RuntimeException
3740
*/
3841
public function __construct(
3942
array $data = [],
@@ -73,8 +76,8 @@ public static function quick(array $data, string $scene = '', bool $startValidat
7376
* @param bool $startValidate 立即开始验证
7477
*
7578
* @return static
76-
* @throws \InvalidArgumentException
77-
* @throws \RuntimeException
79+
* @throws InvalidArgumentException
80+
* @throws RuntimeException
7881
*/
7982
public static function make(
8083
array $data,
@@ -95,8 +98,8 @@ public static function make(
9598
* @param string $scene
9699
*
97100
* @return static
98-
* @throws \InvalidArgumentException
99-
* @throws \RuntimeException
101+
* @throws InvalidArgumentException
102+
* @throws RuntimeException
100103
*/
101104
public static function makeAndValidate(array $data, array $rules = [], array $translates = [], string $scene = '')
102105
{
@@ -112,8 +115,8 @@ public static function makeAndValidate(array $data, array $rules = [], array $tr
112115
* @param string $scene
113116
*
114117
* @return static
115-
* @throws \InvalidArgumentException
116-
* @throws \RuntimeException
118+
* @throws InvalidArgumentException
119+
* @throws RuntimeException
117120
*/
118121
public static function check(array $data, array $rules = [], array $translates = [], string $scene = '')
119122
{

src/Filter/FilteringTrait.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88

99
namespace Inhere\Validate\Filter;
1010

11+
use function function_exists;
1112
use Inhere\Validate\Helper;
13+
use InvalidArgumentException;
14+
use function is_object;
15+
use function is_string;
16+
use function method_exists;
17+
use function trim;
1218

1319
/**
1420
* Trait FilteringTrait
@@ -39,23 +45,23 @@ trait FilteringTrait
3945
* ]
4046
*
4147
* @return mixed
42-
* @throws \InvalidArgumentException
48+
* @throws InvalidArgumentException
4349
*/
4450
protected function valueFiltering($value, $filters)
4551
{
46-
$filters = \is_string($filters) ? Filters::explode($filters, '|') : $filters;
52+
$filters = is_string($filters) ? Filters::explode($filters, '|') : $filters;
4753

4854
foreach ($filters as $key => $filter) {
4955
// key is a filter. ['myFilter' => ['arg1', 'arg2']]
50-
if (\is_string($key)) {
56+
if (is_string($key)) {
5157
$args = (array)$filter;
5258
$value = $this->callStringCallback($key, $value, ...$args);
5359

5460
// closure
55-
} elseif (\is_object($filter) && \method_exists($filter, '__invoke')) {
61+
} elseif (is_object($filter) && method_exists($filter, '__invoke')) {
5662
$value = $filter($value);
5763
// string, trim, ....
58-
} elseif (\is_string($filter)) {
64+
} elseif (is_string($filter)) {
5965
$value = $this->callStringCallback($filter, $value);
6066

6167
// e.g ['Class', 'method'],
@@ -72,7 +78,7 @@ protected function valueFiltering($value, $filters)
7278
* @param array ...$args
7379
*
7480
* @return mixed
75-
* @throws \InvalidArgumentException
81+
* @throws InvalidArgumentException
7682
*/
7783
protected function callStringCallback(string $filter, ...$args)
7884
{
@@ -83,7 +89,7 @@ protected function callStringCallback(string $filter, ...$args)
8389
if ($callback = $this->getFilter($filter)) {
8490
$value = $callback(...$args);
8591
// if $filter is a custom method of the subclass.
86-
} elseif (\method_exists($this, $filter . 'Filter')) {
92+
} elseif (method_exists($this, $filter . 'Filter')) {
8793
$filter .= 'Filter';
8894
$value = $this->$filter(...$args);
8995

@@ -93,14 +99,14 @@ protected function callStringCallback(string $filter, ...$args)
9399

94100
// if $filter is a custom add callback in the property {@see $_filters}.
95101
// $filter is a method of the class 'FilterList'
96-
} elseif (\method_exists(Filters::class, $filterName)) {
102+
} elseif (method_exists(Filters::class, $filterName)) {
97103
$value = Filters::$filterName(...$args);
98104

99105
// it is function name
100-
} elseif (\function_exists($filter)) {
106+
} elseif (function_exists($filter)) {
101107
$value = $filter(...$args);
102108
} else {
103-
throw new \InvalidArgumentException("The filter [$filter] don't exists!");
109+
throw new InvalidArgumentException("The filter [$filter] don't exists!");
104110
}
105111

106112
return $value;
@@ -139,7 +145,7 @@ public function addFilter(string $name, callable $filter): self
139145
*/
140146
public function setFilter(string $name, callable $filter)
141147
{
142-
if ($name = \trim($name)) {
148+
if ($name = trim($name)) {
143149
$this->_filters[$name] = $filter;
144150
}
145151

0 commit comments

Comments
 (0)