Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Pull Request — main (#4854)
by Pedro
36:02 queued 23:20
created

CollectionRepository::getItems()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Backpack\CRUD\app\Library\Components;
4
5
use Backpack\CRUD\app\Library\Components\Interfaces\Components\SmartComponentInterface;
0 ignored issues
show
Bug introduced by
The type Backpack\CRUD\app\Librar...SmartComponentInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Closure;
7
use Illuminate\Support\Collection;
8
9
class CollectionRepository
10
{
11
    public function __construct(private Closure $getCollection, private Closure $saveCollection)
12
    {
13
    }
14
15
    public function addItem($key, $value, $save = true)
16
    {
17
        $items = $this->getItems();
18
        $items[$key] = $value;
19
        ! $save ?: $this->save($items->toArray());
20
    }
21
22
    public function getItems(): Collection
23
    {
24
        if ($this->getCollection) {
25
            $collection = ($this->getCollection)();
26
27
            return collect($collection);
28
        }
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 24 is false. This is incompatible with the type-hinted return Illuminate\Support\Collection. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
29
    }
30
31
    public function removeItem($attribute, $save = true)
32
    {
33
        $items = $this->getItems()->filter(function ($collectionItem, $key) use ($attribute) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

33
        $items = $this->getItems()->filter(function ($collectionItem, /** @scrutinizer ignore-unused */ $key) use ($attribute) {

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

Loading history...
34
            return $collectionItem->getName() !== $attribute;
35
        });
36
37
        ! $save ?: $this->save($items);
38
    }
39
40
    private function save($collection)
41
    {
42
        if (is_callable($this->saveCollection)) {
43
            ($this->saveCollection)($collection);
44
        }
45
    }
46
47
    public function setItemAttributes($key, $attributes)
48
    {
49
        $this->addItem($key, $attributes);
50
    }
51
52
    public function getItemByName($name)
53
    {
54
        return $this->getItems()->first(function ($item, $key) use ($name) {
55
            return $key === $name;
56
        });
57
    }
58
59
    public function replaceItem(SmartComponentInterface $item)
60
    {
61
        $items = $this->removeItem($item, false);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $items is correct as $this->removeItem($item, false) targeting Backpack\CRUD\app\Librar...epository::removeItem() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
The assignment to $items is dead and can be removed.
Loading history...
62
        $items = $this->addItem($item, false);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $items is correct as $this->addItem($item, false) targeting Backpack\CRUD\app\Librar...onRepository::addItem() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
63
64
        $this->save($items);
65
    }
66
67
    public function getAttribute($attribute)
68
    {
69
        return $this->attributes[$attribute];
0 ignored issues
show
Bug Best Practice introduced by
The property attributes does not exist on Backpack\CRUD\app\Librar...ts\CollectionRepository. Did you maybe forget to declare it?
Loading history...
70
    }
71
}
72