GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Larafilter::normalizeFilters()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 3
nc 1
nop 1
1
<?php
2
3
namespace Mjedari\Larafilter;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Support\Str;
7
use ReflectionClass;
8
9
class Larafilter
10
{
11
    /**
12
     * Check if larafilter config file has been published and set.
13
     * @return bool
14
     */
15
    public function configNotPublished()
16
    {
17
        return is_null(config('larafilter'));
18
    }
19
20
    /**
21
     * @param $filters
22
     * @return Collection
23
     */
24
    public function normalizeFilters(array $filters)
25
    {
26
        return collect($filters)->flatMap(function ($value) {
27
            $reflectionClass = (new ReflectionClass($value));
28
            $reflectionProperty = $reflectionClass->getProperty('queryName');
29
            if ($reflectionProperty->class === $value) {
30
                // here filter class has query name
31
                $className = $reflectionClass->getStaticPropertyValue('queryName');
32
            } else {
33
                $className = strtolower(Str::afterLast($value, '\\'));
34
            }
35
36
            $result[$className] = $value;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
37
38
            // Reject if class doesnt exist
39
            if (! class_exists($value)) {
40
                return false;
41
            }
42
43
            return $result;
44
        });
45
    }
46
}
47