88
99namespace Inhere \Validate \Filter ;
1010
11+ use function function_exists ;
1112use 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