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.
Completed
Push — analysis-gO1xaQ ( 94cf7a )
by butschster
07:41
created

VisibleCondition::setVisible()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Traits;
4
5
use Closure;
6
7
trait VisibleCondition
8
{
9
    /**
10
     * @var Closure|null
11
     */
12
    protected $visibleCondition;
13
14
    /**
15
     * @return bool
16
     */
17
    public function isVisible()
18
    {
19
        if (is_bool($this->visibleCondition)) {
0 ignored issues
show
introduced by
The condition is_bool($this->visibleCondition) is always false.
Loading history...
20
            return $this->visibleCondition;
21
        }
22
23
        if (is_callable($this->visibleCondition)) {
24
            return (bool) call_user_func($this->visibleCondition, $this->getModel());
0 ignored issues
show
Bug introduced by
It seems like getModel() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

24
            return (bool) call_user_func($this->visibleCondition, $this->/** @scrutinizer ignore-call */ getModel());
Loading history...
25
        }
26
27
        return true;
28
    }
29
30
    /**
31
     * @param Closure|bool $visibleCondition
32
     *
33
     * @return $this
34
     */
35
    public function setVisible($visibleCondition)
36
    {
37
        $this->visibleCondition = $visibleCondition;
0 ignored issues
show
Documentation Bug introduced by
It seems like $visibleCondition can also be of type boolean. However, the property $visibleCondition is declared as type Closure|null. 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...
38
39
        return $this;
40
    }
41
42
    /**
43
     * @param Closure $condition
44
     *
45
     * @return $this
46
     */
47
    public function setVisibilityCondition(Closure $condition)
48
    {
49
        $this->visibleCondition = $condition;
50
51
        return $this;
52
    }
53
}
54