Completed
Push — master ( d477ef...248726 )
by wen
14:10
created

Tree::getTree()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace Sco\Admin\View;
4
5
use Illuminate\Support\Collection;
6
7
class Tree extends View
8
{
9
    protected $type = 'tree';
10
11
    public function get()
12
    {
13
        $builder = $this->getQuery();
14
        return $this->getTree($builder->get());
0 ignored issues
show
Bug introduced by
It seems like $builder->get() targeting Illuminate\Database\Eloquent\Builder::get() can also be of type array<integer,object<Ill...base\Eloquent\Builder>>; however, Sco\Admin\View\Tree::getTree() does only seem to accept object<Illuminate\Support\Collection>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
15
    }
16
17
    public function getTree(Collection $collection)
18
    {
19
        return $collection->map(function ($item) {
20
            return [
21
                'id' => $item->id,
22
                'title' => $item->name,
23
                'children' => [],
24
            ];
25
        });
26
    }
27
}
28