Passed
Pull Request — master (#11)
by Anton
03:24
created

Addons   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 6
dl 0
loc 58
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A processItem() 0 10 4
A processContents() 0 1 1
B handleAjax() 0 23 5
A handle() 0 10 2
1
<?php
2
3
namespace Modules\Extend\Utils\Handler {
4
5
	use Modules\Extend, Modules\Informer, Ajax, Arr, Language, Request, Template;
6
7
	abstract class Addons extends Extend\Utils\Handler {
8
9
		# Process item
10
11
		protected function processItem(Template\Block $item, array $data) {
12
13
			$browsable = ($data['installed'] && ('' !== $data['browse_url']));
14
15
			$item->getBlock('browse')->class = ($browsable ? 'primary' : 'disabled');
0 ignored issues
show
Documentation introduced by
The property class 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...
16
17
			$item->getBlock('browse')->link = $data['browse_url'];
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...
18
19
			$item->getBlock($data['installed'] ? 'install' : 'uninstall')->disable();
20
		}
21
22
		# Process contents
23
24
		protected function processContents(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...
25
26
		# Handle ajax request
27
28
		protected function handleAjax() {
29
30
			$ajax = Ajax::createResponse();
31
32
			# Process actions
33
34
			if (Request::post('action') === 'install') {
35
36
				$name = Request::post('name');
37
38
				if (!$this->loader->install($name, true)) return $ajax->setError(Language::get(static::$error_install));
39
40
			} else if (Request::post('action') === 'uninstall') {
41
42
				$name = Request::post('name');
43
44
				if (!$this->loader->install($name, false)) return $ajax->setError(Language::get(static::$error_uninstall));
45
			}
46
47
			# ------------------------
48
49
			return $ajax;
50
		}
51
52
		# Handle common request
53
54
		public function handle() {
55
56
			$this->loader = new static::$loader_class;
57
58
			if (Request::isAjax()) return $this->handleAjax();
59
60
			# ------------------------
61
62
			return $this->getContents();
63
		}
64
	}
65
}
66