Completed
Branch 0.2.1 (e70612)
by Anton
09:15
created

Menuitems   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 48
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A processEntity() 0 8 3
A processItem() 0 12 3
1
<?php
2
3
namespace Modules\Entitizer\Listview {
4
5
	use Modules\Entitizer, Template;
6
7
	class Menuitems extends Entitizer\Utils\Listview {
8
9
		use Entitizer\Common\Menuitem;
10
11
		# Listview configuration
12
13
		protected static $lister = 'Modules\Entitizer\Lister\Menuitems';
14
15
		protected static $link = '/admin/content/menuitems';
16
17
		protected static $naming = 'text';
18
19
		protected static $display = CONFIG_ADMIN_MENUITEMS_DISPLAY;
20
21
		protected static $view_main = 'Blocks\Entitizer\Menuitems\Listview\Main';
22
23
		protected static $view_item = 'Blocks\Entitizer\Menuitems\Listview\Item';
24
25
		protected static $view_ajax_main = 'Blocks\Entitizer\Menuitems\Ajax\Main';
26
27
		protected static $view_ajax_item = 'Blocks\Entitizer\Menuitems\Ajax\Item';
28
29
		# Add additional data for specific entity
30
31
		protected function processEntity(Template\Asset\Block $contents) {
32
33
			if ((0 === $this->parent->id) || ('' === $this->parent->link)) {
34
35
				$contents->block('parent')->block('browse')->disable();
36
37
			} else $contents->block('parent')->block('browse')->link = $this->parent->link;
38
		}
39
40
		# Add item additional data
41
42
		protected function processItem(Template\Asset\Block $view, Entitizer\Entity\Menuitem $menuitem, int $children = 0) {
43
44
			$view->icon = ((0 === $children) ? 'bars' : 'folder');
0 ignored issues
show
Documentation introduced by
The property icon does not exist on object<Template\Asset\Block>. 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...
45
46
			$view->position = $menuitem->position;
0 ignored issues
show
Documentation introduced by
The property position does not exist on object<Template\Asset\Block>. 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...
Bug introduced by
The property position does not seem to exist in Modules\Entitizer\Entity\Menuitem.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
47
48
			# Set browse button
49
50
			$view->block('browse')->class = (('' !== $menuitem->link) ? 'primary' : 'disabled');
0 ignored issues
show
Documentation introduced by
The property link does not exist on object<Modules\Entitizer\Entity\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...
51
52
			$view->block('browse')->link = $menuitem->link;
0 ignored issues
show
Bug introduced by
The property link does not seem to exist in Modules\Entitizer\Entity\Menuitem.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
53
		}
54
	}
55
}
56