Completed
Push — master ( 416cb1...222de5 )
by Anton
03:44
created

Page   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B __invoke() 0 46 5
1
<?php
2
3
namespace Modules\Entitizer\Controller {
4
5
	use Modules\Entitizer, Arr;
6
7
	class Page {
8
9
		private $page = null;
10
11
		# Constructor
12
13
		public function __construct(Entitizer\Entity\Page $page) {
14
15
			$this->page = $page;
16
		}
17
18
		# Invoker
19
20
		public function __invoke(array $post) {
21
22
			# Declare variables
23
24
			$parent_id = ''; $title = ''; $name = ''; $visibility = ''; $access = '';
25
26
			$description = ''; $keywords = ''; $robots_index = ''; $robots_follow = ''; $contents = '';
27
28
			# Extract post array
29
30
			extract($post);
31
32
			# Get hash
33
34
			$hash = Arr::encode([$name, Entitizer::get(ENTITY_TYPE_PAGE, $parent_id)->id]);
35
36
			# Check name exists
37
38
			if (false === ($check_name = $this->page->check('hash', $hash))) return 'PAGE_ERROR_MODIFY';
39
40
			if ($check_name === 1) return 'PAGE_ERROR_NAME_DUPLICATE';
41
42
			# Modify page
43
44
			$data = [];
45
46
			$data['parent_id']          = $parent_id;
47
			$data['title']              = $title;
48
			$data['name']               = $name;
49
			$data['visibility']         = $visibility;
50
			$data['access']             = $access;
51
			$data['description']        = $description;
52
			$data['keywords']           = $keywords;
53
			$data['robots_index']       = $robots_index;
54
			$data['robots_follow']      = $robots_follow;
55
			$data['contents']           = $contents;
56
			$data['hash']               = $hash;
57
58
			$modifier = ((0 === $this->page->id) ? 'create' : 'edit');
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in Modules\Entitizer\Utils\Entity. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
59
60
			if (!$this->page->$modifier($data)) return 'PAGE_ERROR_MODIFY';
61
62
			# ------------------------
63
64
			return true;
65
		}
66
	}
67
}
68