These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use Illuminate\Support\Collection; |
||
4 | |||
5 | /* |
||
6 | * Returns true if $callback returns true for every item. If $callback |
||
7 | * is a string or an array, regard it as a validation rule. |
||
8 | * |
||
9 | * @param string|callable $callback |
||
10 | * |
||
11 | * @return bool |
||
12 | */ |
||
13 | Collection::macro('validate', function ($callback): bool { |
||
14 | if (is_string($callback) || is_array($callback)) { |
||
15 | $validationRule = $callback; |
||
16 | |||
17 | $callback = function ($item) use ($validationRule) { |
||
18 | if (! is_array($item)) { |
||
19 | $item = ['default' => $item]; |
||
20 | } |
||
21 | |||
22 | if (! is_array($validationRule)) { |
||
23 | $validationRule = ['default' => $validationRule]; |
||
0 ignored issues
–
show
|
|||
24 | } |
||
25 | |||
26 | return app('validator')->make($item, $validationRule)->passes(); |
||
27 | }; |
||
28 | } |
||
29 | |||
30 | foreach ($this->items as $item) { |
||
31 | if (! $callback($item)) { |
||
32 | return false; |
||
33 | } |
||
34 | } |
||
35 | |||
36 | return true; |
||
37 | }); |
||
38 |
It seems like you are assigning to a variable which was imported through a
use
statement which was not imported by reference.For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.
Change not visible in outer-scope
Change visible in outer-scope