Completed
Push — master ( 3fda7f...fe99a9 )
by Song
02:46
created

Footer::fillTds()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Grid\Tools;
4
5
use Encore\Admin\Grid;
6
use Illuminate\Contracts\Support\Htmlable;
7
use Illuminate\Contracts\Support\Renderable;
8
use Illuminate\Database\Query\Builder;
9
10
class Footer extends AbstractTool
11
{
12
    /**
13
     * @var Builder
14
     */
15
    protected $queryBuilder;
16
17
    /**
18
     * Footer constructor.
19
     *
20
     * @param Grid $grid
21
     */
22
    public function __construct(Grid $grid)
23
    {
24
        $this->grid = $grid;
25
    }
26
27
    /**
28
     * Get model query builder.
29
     *
30
     * @return \Illuminate\Database\Eloquent\Builder
31
     */
32
    public function queryBuilder()
33
    {
34
        if (!$this->queryBuilder) {
35
            $this->queryBuilder = $this->grid->model()->getQueryBuilder();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->grid->model()->getQueryBuilder() can also be of type object<Illuminate\Database\Eloquent\Builder>. However, the property $queryBuilder is declared as type object<Illuminate\Database\Query\Builder>. 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...
36
        }
37
38
        return $this->queryBuilder;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->queryBuilder; of type Illuminate\Database\Eloq...\Database\Query\Builder adds the type Illuminate\Database\Query\Builder to the return on line 38 which is incompatible with the return type documented by Encore\Admin\Grid\Tools\Footer::queryBuilder of type Illuminate\Database\Eloquent\Builder.
Loading history...
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function render()
45
    {
46
        $content = call_user_func($this->grid->footer(), $this->queryBuilder());
47
48
        if (empty($content)) {
49
            return '';
50
        }
51
52
        if ($content instanceof Renderable) {
53
            $content = $content->render();
54
        }
55
56
        if ($content instanceof Htmlable) {
57
            $content = $content->toHtml();
58
        }
59
60
        return <<<HTML
61
    <div class="box-footer clearfix">
62
        {$content}
63
    </div>
64
HTML;
65
    }
66
}
67