Menuitem   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 8
Bugs 0 Features 5
Metric Value
wmc 3
c 8
b 0
f 5
lcom 0
cbo 3
dl 0
loc 52
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A menu() 0 4 1
A makeChildOf() 0 5 1
A isRoot() 0 4 1
1
<?php namespace Modules\Menu\Entities;
2
3
use Dimsav\Translatable\Translatable;
4
use Illuminate\Database\Eloquent\Model;
5
use TypiCMS\NestableTrait;
6
7
class Menuitem extends Model
8
{
9
    use Translatable, NestableTrait;
10
11
    public $translatedAttributes = ['title', 'uri', 'url', 'status'];
12
    protected $fillable = [
13
        'menu_id',
14
        'page_id',
15
        'parent_id',
16
        'position',
17
        'target',
18
        'module_name',
19
        'title',
20
        'uri',
21
        'url',
22
        'status',
23
        'is_root',
24
        'icon'
25
    ];
26
    protected $table = 'menu__menuitems';
27
28
    /**
29
     * For nested collection
30
     *
31
     * @var array
32
     */
33
    public $children = [];
34
35
    public function menu()
36
    {
37
        return $this->belongsTo('Modules\Menu\Entities\Menu');
38
    }
39
40
    /**
41
     * Make the current menu item child of the given root item
42
     * @param Menuitem $rootItem
43
     */
44
    public function makeChildOf(Menuitem $rootItem)
45
    {
46
        $this->parent_id = $rootItem->id;
0 ignored issues
show
Documentation introduced by
The property parent_id does not exist on object<Modules\Menu\Entities\Menuitem>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
Documentation introduced by
The property id does not exist on object<Modules\Menu\Entities\Menuitem>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
47
        $this->save();
48
    }
49
50
    /**
51
     * Check if the current menu item is the root
52
     * @return bool
53
     */
54
    public function isRoot()
55
    {
56
        return (bool) $this->is_root;
0 ignored issues
show
Documentation introduced by
The property is_root does not exist on object<Modules\Menu\Entities\Menuitem>. 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...
57
    }
58
}
59