Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#60)
by Agus
01:07
created

Menu   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 0
loc 99
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 12 2
A getTree() 0 27 5
A customActions() 0 5 1
1
<?php
2
3
namespace Backpack\MenuCRUD\app\Models;
4
5
use Backpack\CRUD\app\Models\Traits\CrudTrait;
6
use Illuminate\Database\Eloquent\Model;
7
8
class Menu extends Model
9
{
10
    use CrudTrait;
11
12
    /*
13
    |--------------------------------------------------------------------------
14
    | GLOBAL VARIABLES
15
    |--------------------------------------------------------------------------
16
    */
17
18
    protected $table = 'menus';
19
    // protected $primaryKey = 'id';
20
    // public $timestamps = false;
21
    protected $guarded = ['id'];
22
    // protected $fillable = [];
23
    // protected $hidden = [];
24
    // protected $dates = [];
25
26
    /*
27
    |--------------------------------------------------------------------------
28
    | FUNCTIONS
29
    |--------------------------------------------------------------------------
30
    */
31
32
    public static function boot()
33
    {
34
        parent::boot();
35
36
        static::updated(function ($menu) {
37
            if ($menu->wasChanged('placement')) {
38
                \Backpack\MenuCRUD\app\Models\Menu::where('placement', $menu->placement)
39
                    ->where('id', '!=', $menu->id)
40
                    ->update(['placement' => null]);
41
            }
42
        });
43
    }
44
45
    /**
46
     * Get all menu items, in a hierarchical collection.
47
     * Supports infinite levels of indentation.
48
     */
49
    public static function getTree($placement)
50
    {
51
        $menu = self::where('placement', $placement)->first();
52
        if ($menu == null) {
53
            return [];
54
        }
55
56
        $menus = \Backpack\MenuCRUD\app\Models\MenuItem::where('menu_id', $menu->id)->orderBy('lft', 'asc')->get()->keyBy('id');
57
58
        // Build the tree using reference method
59
        $flat = [];
60
        $tree = [];
61
62
        foreach ($menus as $primaryKey => $menu) {
63
            if (! isset($flat[$primaryKey])) {
64
                $flat[$primaryKey]['menu_data'] = $menu;
65
            }
66
67
            if ($menu->parent_id != null) {
68
                $flat[$menu->parent_id]['submenus'][$primaryKey] = &$flat[$primaryKey];
69
            } else {
70
                $tree[$primaryKey] = &$flat[$primaryKey];
71
            }
72
        }
73
74
        return $tree;
75
    }
76
77
    public function customActions($crud = false)
0 ignored issues
show
Unused Code introduced by
The parameter $crud 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...
78
    {
79
        return '
80
        <a href="'.backpack_url('menu-item', $this->id).'" class="btn btn-sm btn-link"><i class="la la-list"></i> Menu Items</a>';
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Backpack\MenuCRUD\app\Models\Menu>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
81
    }
82
83
    /*
84
    |--------------------------------------------------------------------------
85
    | RELATIONS
86
    |--------------------------------------------------------------------------
87
    */
88
89
    /*
90
    |--------------------------------------------------------------------------
91
    | SCOPES
92
    |--------------------------------------------------------------------------
93
    */
94
95
    /*
96
    |--------------------------------------------------------------------------
97
    | ACCESSORS
98
    |--------------------------------------------------------------------------
99
    */
100
101
    /*
102
    |--------------------------------------------------------------------------
103
    | MUTATORS
104
    |--------------------------------------------------------------------------
105
    */
106
}
107