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
Branch development (1ea943)
by butschster
05:38
created

Renderable::getView()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Traits;
4
5
use Illuminate\View\View;
6
7
trait Renderable
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $viewPath;
13
14
    /**
15
     * @param string|View $view
16
     *
17
     * @return $this
18
     */
19
    public function setView($view)
20
    {
21
        $this->viewPath = $view;
0 ignored issues
show
Documentation Bug introduced by
It seems like $view can also be of type object<Illuminate\View\View>. However, the property $viewPath 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...
22
23
        return $this;
24
    }
25
26
    /**
27
     * @return View|string
28
     */
29
    public function getView()
30
    {
31
        if (empty($this->viewPath) && property_exists($this, 'view')) {
32
            return $this->view;
0 ignored issues
show
Bug introduced by
The property view does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
        }
34
35
        return $this->viewPath;
36
    }
37
38
39
    /**
40
     * @return string
41
     */
42
    public function __toString()
43
    {
44
        return (string) $this->render();
45
    }
46
47
    /**
48
     * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
49
     */
50
    public function render()
51
    {
52
        return app('sleeping_owl.template')->view(
53
            $this->getView(),
54
            $this->toArray()
0 ignored issues
show
Bug introduced by
It seems like toArray() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
55
        );
56
    }
57
}