@@ -16,7 +16,7 @@ class Underscore implements \ArrayAccess, \Countable, \IteratorAggregate, \JsonS
16
16
*/
17
17
public function __construct ($ data = [])
18
18
{
19
- $ this ->data = is_array ($ data ) ? $ data : Helper::asArray ($ data );
19
+ $ this ->data = \ is_array ($ data ) ? $ data : Helper::asArray ($ data );
20
20
}
21
21
22
22
/**
@@ -62,7 +62,7 @@ public function collect(callable $fn)
62
62
63
63
public function reduce (callable $ fn , $ memo )
64
64
{
65
- return array_reduce ($ this ->data , $ fn , $ memo );
65
+ return \ array_reduce ($ this ->data , $ fn , $ memo );
66
66
}
67
67
68
68
public function foldl (callable $ fn , $ memo )
@@ -77,7 +77,7 @@ public function inject(callable $fn, $memo)
77
77
78
78
public function reduceRight (callable $ fn , $ memo )
79
79
{
80
- return array_reduce (array_reverse ($ this ->data ), $ fn , $ memo );
80
+ return \ array_reduce (\ array_reverse ($ this ->data ), $ fn , $ memo );
81
81
}
82
82
83
83
public function foldr (callable $ fn , $ memo )
@@ -101,7 +101,7 @@ public function detect(callable $fn)
101
101
102
102
public function filter (callable $ fn )
103
103
{
104
- $ data = array_filter ($ this ->data , $ fn , \ARRAY_FILTER_USE_BOTH );
104
+ $ data = \ array_filter ($ this ->data , $ fn , \ARRAY_FILTER_USE_BOTH );
105
105
106
106
return new static ($ data );
107
107
}
@@ -113,15 +113,15 @@ public function select(callable $fn)
113
113
114
114
public function reject (callable $ fn )
115
115
{
116
- $ data = array_filter ($ this ->data , $ this ->negate ($ fn ), \ARRAY_FILTER_USE_BOTH );
116
+ $ data = \ array_filter ($ this ->data , $ this ->negate ($ fn ), \ARRAY_FILTER_USE_BOTH );
117
117
118
118
return new static ($ data );
119
119
}
120
120
121
121
protected function negate (callable $ fn )
122
122
{
123
123
return function () use ($ fn ) {
124
- return !call_user_func_array ($ fn , func_get_args ());
124
+ return !\ call_user_func_array ($ fn , \ func_get_args ());
125
125
};
126
126
}
127
127
@@ -148,12 +148,8 @@ public function any(callable $fn)
148
148
protected function match (callable $ fn , $ all = true )
149
149
{
150
150
foreach ($ this ->data as $ index => $ value ) {
151
- if ($ all && !$ fn ($ value , $ index )) {
152
- return false ;
153
- }
154
-
155
- if (!$ all && $ fn ($ value , $ index )) {
156
- return true ;
151
+ if ($ all ^ $ fn ($ value , $ index )) {
152
+ return !$ all ;
157
153
}
158
154
}
159
155
0 commit comments