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

Basic::processContents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Modules\Extend\Utils\Handler {
4
5
	use Modules\Extend, Modules\Settings, Ajax, Arr, Language, Request, Template, JSON;
6
7
	abstract class Basic extends Extend\Utils\Handler {
8
9
		# Process item
10
11
		protected function processItem(Template\Block $item, array $data) {
12
13
			$item->class = (($data['name'] === $this->loader->data('name')) ? 'positive' : 'grey');
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...
14
		}
15
16
		# Process contents
17
18
		protected function processContents(Template\Block $contents) {
19
20
			$contents->section = $this->loader->section();
0 ignored issues
show
Documentation introduced by
The property section 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...
21
		}
22
23
		# Handle ajax request
24
25
		protected function handleAjax() {
26
27
			$ajax = Ajax::createResponse();
28
29
			# Process actions
30
31
			if (Request::post('action') === 'activate') {
32
33
				if (MODE_DEMO) return $ajax->setError(Language::get('DEMO_MODE_RESTRICTION'));
34
35
				$param = static::$param[$this->loader->section()]; $name = Request::post('name');
36
37
				if (false === Settings::set($param, $name)) return $ajax->setError(Language::get(static::$error_activate));
38
39
				if (false === Settings::save()) return $ajax->setError(Language::get(static::$error_save));
40
41
			} else if (Request::post('action') === 'list') {
42
43
				$ajax->set('items', $this->loader->items());
44
			}
45
46
			# ------------------------
47
48
			return $ajax;
49
		}
50
51
		# Handle common request
52
53
		public function handle() {
54
55
			$this->loader = new static::$loader_class(Request::get('list'));
56
57
			if (Request::isAjax()) return $this->handleAjax();
58
59
			# ------------------------
60
61
			return $this->getContents();
62
		}
63
	}
64
}
65