Menuitem::processEntityParent()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 3
Ratio 50 %

Importance

Changes 0
Metric Value
dl 3
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
/**
4
 * @package Cadmium\System\Modules\Entitizer
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace Modules\Entitizer\Handler\Edit {
11
12
	use Modules\Entitizer, Template;
13
14
	class Menuitem extends Entitizer\Utils\Handler {
15
16
		use Entitizer\Common\Menuitem;
17
18
		protected $_title = 'TITLE_CONTENT_MENUITEMS_EDIT';
19
20
		# Handler configuration
21
22
		protected static $naming = 'text', $naming_new = '';
23
24
		protected static $view = 'Blocks/Entitizer/Menuitems/Main';
25
26
		protected static $form_class = 'Modules\Entitizer\Form\Menuitem';
27
28
		protected static $controller_class = 'Modules\Entitizer\Controller\Menuitem';
29
30
		protected static $message_success_save = 'MENUITEM_SUCCESS_SAVE';
31
32
		protected static $message_error_move = 'MENUITEM_ERROR_MOVE';
33
34
		protected static $message_error_remove = 'MENUITEM_ERROR_REMOVE';
35
36
		protected static $link = '/admin/content/menuitems';
37
38
		/**
39
		 * Add parent's additional data
40
		 */
41
42
		protected function processEntityParent(Template\Block $parent) {
43
44 View Code Duplication
			if (0 !== $this->parent->id) $parent->getBlock('browse')->link = $this->parent->link;
0 ignored issues
show
Documentation introduced by
The property link does not exist on object<Template\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...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Bug introduced by
The property link does not seem to exist in Modules\Entitizer\Utils\Entity.

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...
Documentation introduced by
The property id does not exist on object<Modules\Entitizer\Utils\Entity>. 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...
45
46
			else { $parent->getBlock('browse')->disable(); $parent->getBlock('browse_disabled')->enable(); }
47
		}
48
49
		/**
50
		 * Add additional data for a specific entity
51
		 */
52
53
		protected function processEntity(Template\Block $contents) {}
0 ignored issues
show
Unused Code introduced by
The parameter $contents 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...
54
	}
55
}
56