Completed
Push — master ( 91c709...1f6826 )
by Antonio Carlos
06:01
created

EnumeratesValues::whereNotNull()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace IlluminateAgnostic\Arr\Support\Traits;
4
5
use CachingIterator;
6
use Exception;
7
use IlluminateAgnostic\Arr\Contracts\Support\Arrayable;
8
use IlluminateAgnostic\Arr\Contracts\Support\Jsonable;
9
use IlluminateAgnostic\Arr\Support\Arr;
10
use IlluminateAgnostic\Arr\Support\Collection;
11
use IlluminateAgnostic\Arr\Support\Enumerable;
12
use IlluminateAgnostic\Arr\Support\HigherOrderCollectionProxy;
13
use JsonSerializable;
14
use Symfony\Component\VarDumper\VarDumper;
15
use Traversable;
16
17
/**
18
 * @property-read HigherOrderCollectionProxy $average
19
 * @property-read HigherOrderCollectionProxy $avg
20
 * @property-read HigherOrderCollectionProxy $contains
21
 * @property-read HigherOrderCollectionProxy $each
22
 * @property-read HigherOrderCollectionProxy $every
23
 * @property-read HigherOrderCollectionProxy $filter
24
 * @property-read HigherOrderCollectionProxy $first
25
 * @property-read HigherOrderCollectionProxy $flatMap
26
 * @property-read HigherOrderCollectionProxy $groupBy
27
 * @property-read HigherOrderCollectionProxy $keyBy
28
 * @property-read HigherOrderCollectionProxy $map
29
 * @property-read HigherOrderCollectionProxy $max
30
 * @property-read HigherOrderCollectionProxy $min
31
 * @property-read HigherOrderCollectionProxy $partition
32
 * @property-read HigherOrderCollectionProxy $reject
33
 * @property-read HigherOrderCollectionProxy $some
34
 * @property-read HigherOrderCollectionProxy $sortBy
35
 * @property-read HigherOrderCollectionProxy $sortByDesc
36
 * @property-read HigherOrderCollectionProxy $sum
37
 * @property-read HigherOrderCollectionProxy $unique
38
 */
39
trait EnumeratesValues
40
{
41
    /**
42
     * The methods that can be proxied.
43
     *
44
     * @var array
45
     */
46
    protected static $proxies = [
47
        'average', 'avg', 'contains', 'each', 'every', 'filter', 'first',
48
        'flatMap', 'groupBy', 'keyBy', 'map', 'max', 'min', 'partition',
49
        'reject', 'some', 'sortBy', 'sortByDesc', 'sum', 'unique',
50
    ];
51
52
    /**
53
     * Create a new collection instance if the value isn't one already.
54
     *
55
     * @param  mixed  $items
56
     * @return static
57
     */
58 30
    public static function make($items = [])
59
    {
60 30
        return new static($items);
0 ignored issues
show
Unused Code introduced by
The call to EnumeratesValues::__construct() has too many arguments starting with $items.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
61
    }
62
63
    /**
64
     * Wrap the given value in a collection if applicable.
65
     *
66
     * @param  mixed  $value
67
     * @return static
68
     */
69 14
    public static function wrap($value)
70
    {
71 14
        return $value instanceof Enumerable
72 4
            ? new static($value)
0 ignored issues
show
Unused Code introduced by
The call to EnumeratesValues::__construct() has too many arguments starting with $value.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
73 14
            : new static(Arr::wrap($value));
0 ignored issues
show
Unused Code introduced by
The call to EnumeratesValues::__construct() has too many arguments starting with \IlluminateAgnostic\Arr\Support\Arr::wrap($value).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
74
    }
75
76
    /**
77
     * Get the underlying items from the given collection if applicable.
78
     *
79
     * @param  array|static  $value
80
     * @return array
81
     */
82 6
    public static function unwrap($value)
83
    {
84 6
        return $value instanceof Enumerable ? $value->all() : $value;
85
    }
86
87
    /**
88
     * Alias for the "avg" method.
89
     *
90
     * @param  callable|string|null  $callback
91
     * @return mixed
92
     */
93 6
    public function average($callback = null)
94
    {
95 6
        return $this->avg($callback);
0 ignored issues
show
Bug introduced by
It seems like avg() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
96
    }
97
98
    /**
99
     * Alias for the "contains" method.
100
     *
101
     * @param  mixed  $key
102
     * @param  mixed  $operator
103
     * @param  mixed  $value
104
     * @return bool
105
     */
106 2
    public function some($key, $operator = null, $value = null)
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $operator is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
107
    {
108 2
        return $this->contains(...func_get_args());
0 ignored issues
show
Bug introduced by
The method contains() does not exist on IlluminateAgnostic\Arr\S...Traits\EnumeratesValues. Did you maybe mean containsStrict()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
109
    }
110
111
    /**
112
     * Determine if an item exists, using strict comparison.
113
     *
114
     * @param  mixed  $key
115
     * @param  mixed  $value
116
     * @return bool
117
     */
118 2
    public function containsStrict($key, $value = null)
119
    {
120 2
        if (func_num_args() === 2) {
121
            return $this->contains(function ($item) use ($key, $value) {
0 ignored issues
show
Bug introduced by
The method contains() does not exist on IlluminateAgnostic\Arr\S...Traits\EnumeratesValues. Did you maybe mean containsStrict()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
122 2
                return data_get($item, $key) === $value;
123 2
            });
124
        }
125
126 2
        if ($this->useAsCallable($key)) {
127 2
            return ! is_null($this->first($key));
0 ignored issues
show
Bug introduced by
It seems like first() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
128
        }
129
130 2
        foreach ($this as $item) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<IlluminateAgnostic\...raits\EnumeratesValues> is not traversable.
Loading history...
131 2
            if ($item === $key) {
132 2
                return true;
133
            }
134
        }
135
136 2
        return false;
137
    }
138
139
    /**
140
     * Dump the items and end the script.
141
     *
142
     * @param  mixed  ...$args
143
     * @return void
144
     */
145
    public function dd(...$args)
146
    {
147
        call_user_func_array([$this, 'dump'], $args);
148
149
        die(1);
150
    }
151
152
    /**
153
     * Dump the items.
154
     *
155
     * @return $this
156
     */
157
    public function dump()
158
    {
159
        (new static(func_get_args()))
0 ignored issues
show
Unused Code introduced by
The call to EnumeratesValues::__construct() has too many arguments starting with func_get_args().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Bug introduced by
It seems like push() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
160
            ->push($this)
161
            ->each(function ($item) {
162
                VarDumper::dump($item);
163
            });
164
165
        return $this;
166
    }
167
168
    /**
169
     * Execute a callback over each item.
170
     *
171
     * @param  callable  $callback
172
     * @return $this
173
     */
174 15
    public function each(callable $callback)
175
    {
176 15
        foreach ($this as $key => $item) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<IlluminateAgnostic\...raits\EnumeratesValues> is not traversable.
Loading history...
177 15
            if ($callback($item, $key) === false) {
178 4
                break;
179
            }
180
        }
181
182 15
        return $this;
183
    }
184
185
    /**
186
     * Execute a callback over each nested chunk of items.
187
     *
188
     * @param  callable  $callback
189
     * @return static
190
     */
191 2
    public function eachSpread(callable $callback)
192
    {
193
        return $this->each(function ($chunk, $key) use ($callback) {
194 2
            $chunk[] = $key;
195
196 2
            return $callback(...$chunk);
197 2
        });
198
    }
199
200
    /**
201
     * Determine if all items pass the given truth test.
202
     *
203
     * @param  string|callable  $key
204
     * @param  mixed  $operator
205
     * @param  mixed  $value
206
     * @return bool
207
     */
208 2
    public function every($key, $operator = null, $value = null)
0 ignored issues
show
Unused Code introduced by
The parameter $operator is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
209
    {
210 2
        if (func_num_args() === 1) {
211 2
            $callback = $this->valueRetriever($key);
212
213 2
            foreach ($this as $k => $v) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<IlluminateAgnostic\...raits\EnumeratesValues> is not traversable.
Loading history...
214 2
                if (! $callback($v, $k)) {
215 2
                    return false;
216
                }
217
            }
218
219 2
            return true;
220
        }
221
222 2
        return $this->every($this->operatorForWhere(...func_get_args()));
0 ignored issues
show
Documentation introduced by
func_get_args() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
223
    }
224
225
    /**
226
     * Get the first item by the given key value pair.
227
     *
228
     * @param  string  $key
229
     * @param  mixed  $operator
230
     * @param  mixed  $value
231
     * @return mixed
232
     */
233 2
    public function firstWhere($key, $operator = null, $value = null)
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $operator is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
234
    {
235 2
        return $this->first($this->operatorForWhere(...func_get_args()));
0 ignored issues
show
Documentation introduced by
func_get_args() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Bug introduced by
It seems like first() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
236
    }
237
238
    /**
239
     * Determine if the collection is not empty.
240
     *
241
     * @return bool
242
     */
243 18
    public function isNotEmpty()
244
    {
245 18
        return ! $this->isEmpty();
0 ignored issues
show
Bug introduced by
It seems like isEmpty() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
246
    }
247
248
    /**
249
     * Run a map over each nested chunk of items.
250
     *
251
     * @param  callable  $callback
252
     * @return static
253
     */
254 2
    public function mapSpread(callable $callback)
255
    {
256
        return $this->map(function ($chunk, $key) use ($callback) {
0 ignored issues
show
Bug introduced by
It seems like map() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
257 2
            $chunk[] = $key;
258
259 2
            return $callback(...$chunk);
260 2
        });
261
    }
262
263
    /**
264
     * Run a grouping map over the items.
265
     *
266
     * The callback should return an associative array with a single key/value pair.
267
     *
268
     * @param  callable  $callback
269
     * @return static
270
     */
271 4
    public function mapToGroups(callable $callback)
272
    {
273 4
        $groups = $this->mapToDictionary($callback);
0 ignored issues
show
Bug introduced by
It seems like mapToDictionary() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
274
275 4
        return $groups->map([$this, 'make']);
276
    }
277
278
    /**
279
     * Map a collection and flatten the result by a single level.
280
     *
281
     * @param  callable  $callback
282
     * @return static
283
     */
284 2
    public function flatMap(callable $callback)
285
    {
286 2
        return $this->map($callback)->collapse();
0 ignored issues
show
Bug introduced by
It seems like map() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
287
    }
288
289
    /**
290
     * Map the values into a new class.
291
     *
292
     * @param  string  $class
293
     * @return static
294
     */
295 2
    public function mapInto($class)
296
    {
297
        return $this->map(function ($value, $key) use ($class) {
0 ignored issues
show
Bug introduced by
It seems like map() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
298 2
            return new $class($value, $key);
299 2
        });
300
    }
301
302
    /**
303
     * Get the min value of a given key.
304
     *
305
     * @param  callable|string|null  $callback
306
     * @return mixed
307
     */
308 2 View Code Duplication
    public function min($callback = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
309
    {
310 2
        $callback = $this->valueRetriever($callback);
311
312
        return $this->map(function ($value) use ($callback) {
0 ignored issues
show
Bug introduced by
It seems like map() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
313 2
            return $callback($value);
314
        })->filter(function ($value) {
315 2
            return ! is_null($value);
316
        })->reduce(function ($result, $value) {
317 2
            return is_null($result) || $value < $result ? $value : $result;
318 2
        });
319
    }
320
321
    /**
322
     * Get the max value of a given key.
323
     *
324
     * @param  callable|string|null  $callback
325
     * @return mixed
326
     */
327 2 View Code Duplication
    public function max($callback = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
328
    {
329 2
        $callback = $this->valueRetriever($callback);
330
331
        return $this->filter(function ($value) {
0 ignored issues
show
Bug introduced by
It seems like filter() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
332 2
            return ! is_null($value);
333
        })->reduce(function ($result, $item) use ($callback) {
334 2
            $value = $callback($item);
335
336 2
            return is_null($result) || $value > $result ? $value : $result;
337 2
        });
338
    }
339
340
    /**
341
     * "Paginate" the collection by slicing it into a smaller collection.
342
     *
343
     * @param  int  $page
344
     * @param  int  $perPage
345
     * @return static
346
     */
347 2
    public function forPage($page, $perPage)
348
    {
349 2
        $offset = max(0, ($page - 1) * $perPage);
350
351 2
        return $this->slice($offset, $perPage);
0 ignored issues
show
Bug introduced by
It seems like slice() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
352
    }
353
354
    /**
355
     * Partition the collection into two arrays using the given callback or key.
356
     *
357
     * @param  callable|string  $key
358
     * @param  mixed  $operator
359
     * @param  mixed  $value
360
     * @return static
361
     */
362 14
    public function partition($key, $operator = null, $value = null)
0 ignored issues
show
Unused Code introduced by
The parameter $operator is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
363
    {
364 14
        $passed = [];
365 14
        $failed = [];
366
367 14
        $callback = func_num_args() === 1
368 12
                ? $this->valueRetriever($key)
369 14
                : $this->operatorForWhere(...func_get_args());
0 ignored issues
show
Documentation introduced by
func_get_args() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
370
371 14
        foreach ($this as $key => $item) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<IlluminateAgnostic\...raits\EnumeratesValues> is not traversable.
Loading history...
372 12
            if ($callback($item, $key)) {
373 12
                $passed[$key] = $item;
374
            } else {
375 12
                $failed[$key] = $item;
376
            }
377
        }
378
379 14
        return new static([new static($passed), new static($failed)]);
0 ignored issues
show
Unused Code introduced by
The call to EnumeratesValues::__construct() has too many arguments starting with $passed.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to EnumeratesValues::__construct() has too many arguments starting with $failed.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to EnumeratesValues::__construct() has too many arguments starting with array(new static($passed), new static($failed)).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
380
    }
381
382
    /**
383
     * Get the sum of the given values.
384
     *
385
     * @param  callable|string|null  $callback
386
     * @return mixed
387
     */
388 16
    public function sum($callback = null)
389
    {
390 16
        if (is_null($callback)) {
391
            $callback = function ($value) {
392 12
                return $value;
393 12
            };
394
        } else {
395 4
            $callback = $this->valueRetriever($callback);
396
        }
397
398
        return $this->reduce(function ($result, $item) use ($callback) {
0 ignored issues
show
Bug introduced by
It seems like reduce() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
399 14
            return $result + $callback($item);
400 16
        }, 0);
401
    }
402
403
    /**
404
     * Apply the callback if the value is truthy.
405
     *
406
     * @param  bool|mixed  $value
407
     * @param  callable  $callback
408
     * @param  callable|null  $default
409
     * @return static|mixed
410
     */
411 24
    public function when($value, callable $callback, callable $default = null)
412
    {
413 24
        if ($value) {
414 16
            return $callback($this, $value);
415 20
        } elseif ($default) {
416 8
            return $default($this, $value);
417
        }
418
419 12
        return $this;
420
    }
421
422
    /**
423
     * Apply the callback if the collection is empty.
424
     *
425
     * @param  callable  $callback
426
     * @param  callable|null  $default
427
     * @return static|mixed
428
     */
429 8
    public function whenEmpty(callable $callback, callable $default = null)
430
    {
431 8
        return $this->when($this->isEmpty(), $callback, $default);
0 ignored issues
show
Bug introduced by
It seems like isEmpty() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
432
    }
433
434
    /**
435
     * Apply the callback if the collection is not empty.
436
     *
437
     * @param  callable  $callback
438
     * @param  callable|null  $default
439
     * @return static|mixed
440
     */
441 8
    public function whenNotEmpty(callable $callback, callable $default = null)
442
    {
443 8
        return $this->when($this->isNotEmpty(), $callback, $default);
444
    }
445
446
    /**
447
     * Apply the callback if the value is falsy.
448
     *
449
     * @param  bool  $value
450
     * @param  callable  $callback
451
     * @param  callable|null  $default
452
     * @return static|mixed
453
     */
454 4
    public function unless($value, callable $callback, callable $default = null)
455
    {
456 4
        return $this->when(! $value, $callback, $default);
457
    }
458
459
    /**
460
     * Apply the callback unless the collection is empty.
461
     *
462
     * @param  callable  $callback
463
     * @param  callable|null  $default
464
     * @return static|mixed
465
     */
466 4
    public function unlessEmpty(callable $callback, callable $default = null)
467
    {
468 4
        return $this->whenNotEmpty($callback, $default);
469
    }
470
471
    /**
472
     * Apply the callback unless the collection is not empty.
473
     *
474
     * @param  callable  $callback
475
     * @param  callable|null  $default
476
     * @return static|mixed
477
     */
478 4
    public function unlessNotEmpty(callable $callback, callable $default = null)
479
    {
480 4
        return $this->whenEmpty($callback, $default);
481
    }
482
483
    /**
484
     * Filter items by the given key value pair.
485
     *
486
     * @param  string  $key
487
     * @param  mixed  $operator
488
     * @param  mixed  $value
489
     * @return static
490
     */
491 14
    public function where($key, $operator = null, $value = null)
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $operator is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
492
    {
493 14
        return $this->filter($this->operatorForWhere(...func_get_args()));
0 ignored issues
show
Documentation introduced by
func_get_args() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Bug introduced by
It seems like filter() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
494
    }
495
496
    /**
497
     * Filter items where the given key is not null.
498
     *
499
     * @param  string|null  $key
500
     * @return static
501
     */
502 4
    public function whereNull($key = null)
503
    {
504 4
        return $this->whereStrict($key, null);
505
    }
506
507
    /**
508
     * Filter items where the given key is null.
509
     *
510
     * @param  string|null  $key
511
     * @return static
512
     */
513 4
    public function whereNotNull($key = null)
514
    {
515 4
        return $this->where($key, '!==', null);
516
    }
517
518
    /**
519
     * Filter items by the given key value pair using strict comparison.
520
     *
521
     * @param  string  $key
522
     * @param  mixed  $value
523
     * @return static
524
     */
525 6
    public function whereStrict($key, $value)
526
    {
527 6
        return $this->where($key, '===', $value);
528
    }
529
530
    /**
531
     * Filter items by the given key value pair.
532
     *
533
     * @param  string  $key
534
     * @param  mixed  $values
535
     * @param  bool  $strict
536
     * @return static
537
     */
538 4 View Code Duplication
    public function whereIn($key, $values, $strict = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
539
    {
540 4
        $values = $this->getArrayableItems($values);
541
542
        return $this->filter(function ($item) use ($key, $values, $strict) {
0 ignored issues
show
Bug introduced by
It seems like filter() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
543 4
            return in_array(data_get($item, $key), $values, $strict);
544 4
        });
545
    }
546
547
    /**
548
     * Filter items by the given key value pair using strict comparison.
549
     *
550
     * @param  string  $key
551
     * @param  mixed  $values
552
     * @return static
553
     */
554 2
    public function whereInStrict($key, $values)
555
    {
556 2
        return $this->whereIn($key, $values, true);
557
    }
558
559
    /**
560
     * Filter items such that the value of the given key is between the given values.
561
     *
562
     * @param  string  $key
563
     * @param  array  $values
564
     * @return static
565
     */
566 2
    public function whereBetween($key, $values)
567
    {
568 2
        return $this->where($key, '>=', reset($values))->where($key, '<=', end($values));
569
    }
570
571
    /**
572
     * Filter items such that the value of the given key is not between the given values.
573
     *
574
     * @param  string  $key
575
     * @param  array  $values
576
     * @return static
577
     */
578 2
    public function whereNotBetween($key, $values)
579
    {
580
        return $this->filter(function ($item) use ($key, $values) {
0 ignored issues
show
Bug introduced by
It seems like filter() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
581 2
            return data_get($item, $key) < reset($values) || data_get($item, $key) > end($values);
582 2
        });
583
    }
584
585
    /**
586
     * Filter items by the given key value pair.
587
     *
588
     * @param  string  $key
589
     * @param  mixed  $values
590
     * @param  bool  $strict
591
     * @return static
592
     */
593 4 View Code Duplication
    public function whereNotIn($key, $values, $strict = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
594
    {
595 4
        $values = $this->getArrayableItems($values);
596
597
        return $this->reject(function ($item) use ($key, $values, $strict) {
598 4
            return in_array(data_get($item, $key), $values, $strict);
599 4
        });
600
    }
601
602
    /**
603
     * Filter items by the given key value pair using strict comparison.
604
     *
605
     * @param  string  $key
606
     * @param  mixed  $values
607
     * @return static
608
     */
609 2
    public function whereNotInStrict($key, $values)
610
    {
611 2
        return $this->whereNotIn($key, $values, true);
612
    }
613
614
    /**
615
     * Filter the items, removing any items that don't match the given type.
616
     *
617
     * @param  string  $type
618
     * @return static
619
     */
620 2
    public function whereInstanceOf($type)
621
    {
622
        return $this->filter(function ($value) use ($type) {
0 ignored issues
show
Bug introduced by
It seems like filter() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
623 2
            return $value instanceof $type;
624 2
        });
625
    }
626
627
    /**
628
     * Pass the collection to the given callback and return the result.
629
     *
630
     * @param  callable  $callback
631
     * @return mixed
632
     */
633 2
    public function pipe(callable $callback)
634
    {
635 2
        return $callback($this);
636
    }
637
638
    /**
639
     * Pass the collection to the given callback and then return it.
640
     *
641
     * @param  callable  $callback
642
     * @return $this
643
     */
644 2
    public function tap(callable $callback)
645
    {
646 2
        $callback(clone $this);
647
648 2
        return $this;
649
    }
650
651
    /**
652
     * Create a collection of all elements that do not pass a given truth test.
653
     *
654
     * @param  callable|mixed  $callback
655
     * @return static
656
     */
657 26
    public function reject($callback = true)
658
    {
659 26
        $useAsCallable = $this->useAsCallable($callback);
660
661
        return $this->filter(function ($value, $key) use ($callback, $useAsCallable) {
0 ignored issues
show
Bug introduced by
It seems like filter() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
662 26
            return $useAsCallable
663 24
                ? ! $callback($value, $key)
664 26
                : $value != $callback;
665 26
        });
666
    }
667
668
    /**
669
     * Return only unique items from the collection array.
670
     *
671
     * @param  string|callable|null  $key
672
     * @param  bool  $strict
673
     * @return static
674
     */
675 18
    public function unique($key = null, $strict = false)
676
    {
677 18
        $callback = $this->valueRetriever($key);
678
679 18
        $exists = [];
680
681
        return $this->reject(function ($item, $key) use ($callback, $strict, &$exists) {
682 18
            if (in_array($id = $callback($item, $key), $exists, $strict)) {
683 18
                return true;
684
            }
685
686 18
            $exists[] = $id;
687 18
        });
688
    }
689
690
    /**
691
     * Return only unique items from the collection array using strict comparison.
692
     *
693
     * @param  string|callable|null  $key
694
     * @return static
695
     */
696 2
    public function uniqueStrict($key = null)
697
    {
698 2
        return $this->unique($key, true);
699
    }
700
701
    /**
702
     * Collect the values into a collection.
703
     *
704
     * @return \IlluminateAgnostic\Arr\Support\Collection
705
     */
706 86
    public function collect()
707
    {
708 86
        return new Collection($this->all());
0 ignored issues
show
Bug introduced by
It seems like all() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
709
    }
710
711
    /**
712
     * Get the collection of items as a plain array.
713
     *
714
     * @return array
715
     */
716 121
    public function toArray()
717
    {
718
        return $this->map(function ($value) {
0 ignored issues
show
Bug introduced by
It seems like map() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
719 115
            return $value instanceof Arrayable ? $value->toArray() : $value;
720 121
        })->all();
721
    }
722
723
    /**
724
     * Convert the object into something JSON serializable.
725
     *
726
     * @return array
727
     */
728 8
    public function jsonSerialize()
729
    {
730
        return array_map(function ($value) {
731 8
            if ($value instanceof JsonSerializable) {
0 ignored issues
show
Bug introduced by
The class JsonSerializable does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
732 4
                return $value->jsonSerialize();
733 8
            } elseif ($value instanceof Jsonable) {
734 2
                return json_decode($value->toJson(), true);
735 8
            } elseif ($value instanceof Arrayable) {
736 4
                return $value->toArray();
737
            }
738
739 6
            return $value;
740 8
        }, $this->all());
0 ignored issues
show
Bug introduced by
It seems like all() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
741
    }
742
743
    /**
744
     * Get the collection of items as JSON.
745
     *
746
     * @param  int  $options
747
     * @return string
748
     */
749 8
    public function toJson($options = 0)
750
    {
751 8
        return json_encode($this->jsonSerialize(), $options);
752
    }
753
754
    /**
755
     * Get a CachingIterator instance.
756
     *
757
     * @param  int  $flags
758
     * @return \CachingIterator
759
     */
760 2
    public function getCachingIterator($flags = CachingIterator::CALL_TOSTRING)
761
    {
762 2
        return new CachingIterator($this->getIterator(), $flags);
0 ignored issues
show
Bug introduced by
It seems like getIterator() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
763
    }
764
765
    /**
766
     * Count the number of items in the collection using a given truth test.
767
     *
768
     * @param  callable|null  $callback
769
     * @return static
770
     */
771 4
    public function countBy($callback = null)
772
    {
773 4
        if (is_null($callback)) {
774
            $callback = function ($value) {
775 2
                return $value;
776 2
            };
777
        }
778
779
        return new static($this->groupBy($callback)->map(function ($value) {
0 ignored issues
show
Bug introduced by
It seems like groupBy() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Unused Code introduced by
The call to EnumeratesValues::__construct() has too many arguments starting with $this->groupBy($callback...urn $value->count(); }).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
780 4
            return $value->count();
781 4
        }));
782
    }
783
784
    /**
785
     * Convert the collection to its string representation.
786
     *
787
     * @return string
788
     */
789 6
    public function __toString()
790
    {
791 6
        return $this->toJson();
792
    }
793
794
    /**
795
     * Add a method to the list of proxied methods.
796
     *
797
     * @param  string  $method
798
     * @return void
799
     */
800 2
    public static function proxy($method)
801
    {
802 2
        static::$proxies[] = $method;
803 2
    }
804
805
    /**
806
     * Dynamically access collection proxies.
807
     *
808
     * @param  string  $key
809
     * @return mixed
810
     *
811
     * @throws \Exception
812
     */
813 33
    public function __get($key)
814
    {
815 33
        if (! in_array($key, static::$proxies)) {
816 2
            throw new Exception("Property [{$key}] does not exist on this collection instance.");
817
        }
818
819 31
        return new HigherOrderCollectionProxy($this, $key);
820
    }
821
822
    /**
823
     * Results array of items from Collection or Arrayable.
824
     *
825
     * @param  mixed  $items
826
     * @return array
827
     */
828 497
    protected function getArrayableItems($items)
829
    {
830 497
        if (is_array($items)) {
831 487
            return $items;
832 91
        } elseif ($items instanceof Enumerable) {
833 57
            return $items->all();
834 36
        } elseif ($items instanceof Arrayable) {
835 2
            return $items->toArray();
836 36
        } elseif ($items instanceof Jsonable) {
837 2
            return json_decode($items->toJson(), true);
838 36
        } elseif ($items instanceof JsonSerializable) {
0 ignored issues
show
Bug introduced by
The class JsonSerializable does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
839 2
            return (array) $items->jsonSerialize();
840 34
        } elseif ($items instanceof Traversable) {
841 4
            return iterator_to_array($items);
842
        }
843
844 30
        return (array) $items;
845
    }
846
847
    /**
848
     * Get an operator checker callback.
849
     *
850
     * @param  string  $key
851
     * @param  string|null  $operator
852
     * @param  mixed  $value
853
     * @return \Closure
854
     */
855 26
    protected function operatorForWhere($key, $operator = null, $value = null)
856
    {
857 26
        if (func_num_args() === 1) {
858 2
            $value = true;
859
860 2
            $operator = '=';
861
        }
862
863 26
        if (func_num_args() === 2) {
864 12
            $value = $operator;
865
866 12
            $operator = '=';
867
        }
868
869
        return function ($item) use ($key, $operator, $value) {
870 26
            $retrieved = data_get($item, $key);
871
872
            $strings = array_filter([$retrieved, $value], function ($value) {
873 26
                return is_string($value) || (is_object($value) && method_exists($value, '__toString'));
874 26
            });
875
876 26
            if (count($strings) < 2 && count(array_filter([$retrieved, $value], 'is_object')) == 1) {
877 2
                return in_array($operator, ['!=', '<>', '!==']);
878
            }
879
880 26
            switch ($operator) {
881
                default:
882 26
                case '=':
883 26
                case '==':  return $retrieved == $value;
884 20
                case '!=':
885 20
                case '<>':  return $retrieved != $value;
886 20
                case '<':   return $retrieved < $value;
887 20
                case '>':   return $retrieved > $value;
888 20
                case '<=':  return $retrieved <= $value;
889 20
                case '>=':  return $retrieved >= $value;
890 14
                case '===': return $retrieved === $value;
891 6
                case '!==': return $retrieved !== $value;
892
            }
893 26
        };
894
    }
895
896
    /**
897
     * Determine if the given value is callable, but not a string.
898
     *
899
     * @param  mixed  $value
900
     * @return bool
901
     */
902 108
    protected function useAsCallable($value)
903
    {
904 108
        return ! is_string($value) && is_callable($value);
905
    }
906
907
    /**
908
     * Get a value retrieving callback.
909
     *
910
     * @param  callable|string|null  $value
911
     * @return callable
912
     */
913 85
    protected function valueRetriever($value)
914
    {
915 85
        if ($this->useAsCallable($value)) {
916 53
            return $value;
917
        }
918
919
        return function ($item) use ($value) {
920 49
            return data_get($item, $value);
0 ignored issues
show
Documentation introduced by
$value is of type callable|null, but the function expects a string|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
921 51
        };
922
    }
923
}
924