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.

Menus::transform()   B
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 44
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 27
nc 6
nop 2
dl 0
loc 44
rs 8.5806
c 0
b 0
f 0
1
<?php
2
namespace Afrittella\BackProject\Repositories;
3
4
class Menus extends Base
5
{
6
    function model()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
7
    {
8
        return 'Afrittella\BackProject\Models\Menu';
9
    }
10
11
    public function all($columns = ['*'])
12
    {
13
        return $this->model->withDepth()->defaultOrder()->whereIsRoot()->select($columns)->get();
14
    }
15
16
    public function children($id)
17
    {
18
        return $this->model->withDepth()->defaultOrder()->descendantsOf($id)->where('parent_id', '=', $id);
19
    }
20
21
    public function find($id, $columns = array('*'))
22
    {
23
        $this->applyCriteria();
24
        return $this->model->withDepth()->find($id, $columns);
25
    }
26
27
    /**
28
     * @param string $name
29
     */
30
    public function tree($name)
31
    {
32
        $root = $this->findBy('name', $name);
33
        $tree = false;
34
35
        if (!empty($root)) {
36
            $tree = $this->model->withDepth()->defaultOrder()->descendantsOf($root->id)->toTree();
37
        }
38
39
        return $tree;
40
    }
41
42
    public function moveUp($id)
43
    {
44
        $menu = $this->model->find($id);
45
        return $menu->up();
46
    }
47
48
    public function moveDown($id)
49
    {
50
        $menu = $this->model->find($id);
51
        return $menu->down();
52
    }
53
54
    public function transform($data = [], $options = [])
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56
        if (empty($data)) {
57
            $data = $this->all();
58
        }
59
60
        // Table header
61
        $head = [
62
            'columns' => [
63
                trans('back-project::menus.name'),
64
                trans('back-project::menus.title'),
65
                trans('back-project::menus.route'),
66
                trans('back-project::menus.icon'),
67
                trans('back-project::crud.actions'),
68
            ]
69
        ];
70
71
        $body = [];
72
73
        foreach ($data as $row):
74
            $actions = [
75
                'edit' => ['url' => route('bp.menus.edit', [$row->id])]
76
            ];
77
78
            if (!$row->is_protected) {
79
                $actions['delete'] = ['url' => route('bp.menus.delete', [$row->id])];
80
            }
81
82
            $body[] = [
83
                'columns' => [
84
                    ['content' => $row->name],
85
                    ['content' => $row->description],
86
                    ['content' => $row->route],
87
                    ['content' => $row->icon],
88
                    ['content' => false, 'actions' => $actions],
89
                ]
90
            ];
91
        endforeach;
92
93
        return [
94
            'head' => $head,
95
            'body' => $body
96
        ];
97
    }
98
99
}
100