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.

RelatedLink::setModel()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 2
nop 1
dl 0
loc 18
ccs 0
cts 14
cp 0
crap 20
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Display\Column;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class RelatedLink extends Link
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $view = 'column.link';
13
14
    /**
15
     * @var string
16
     */
17
    protected $originalName;
18
19
    /**
20
     * @var bool
21
     */
22
    protected $orderable = false;
23
24
    /**
25
     * @param \Closure|null|string $name
26
     * @param null|string $label
27
     */
28
    public function __construct($name, $label = null, $small = null)
29
    {
30
        parent::__construct($name, $label, $small);
31
        $this->originalName = $name;
0 ignored issues
show
Documentation Bug introduced by
It seems like $name can also be of type Closure. However, the property $originalName is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
32
    }
33
34
    /**
35
     * @param Model $model
36
     *
37
     * @return Link
38
     */
39
    public function setModel(Model $model)
40
    {
41
        if (strpos($this->originalName, '.') !== false) {
42
            $parts = explode('.', $this->originalName);
43
            $name = array_pop($parts);
44
45
            while ($parts) {
46
                $part = array_shift($parts);
47
                $relation = $model->getAttribute($part);
48
49
                if ($relation instanceof Model) {
50
                    $model = $relation;
51
                    $this->setName($name);
52
                }
53
            }
54
        }
55
56
        return parent::setModel($model);
57
    }
58
}
59