Passed
Push — master ( e0d6a2...2ec881 )
by Anton
05:25 queued 02:20
created

View   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 72
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 4 2
A _display() 0 20 1
A _navigate() 0 20 1
A __construct() 0 4 1
1
<?php
2
3
/**
4
 * @package Cadmium\System\Frames\Admin
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace Frames\Admin {
11
12
	use Modules\Extend, Ajax, Language, Template;
13
14
	abstract class View extends \Utils\View {
15
16
		protected $view = '', $status = STATUS_CODE_200, $title = '';
17
18
		/**
19
		 * Get the page title
20
		 */
21
22
		private function getTitle() : string {
23
24
			return ((('' !== $this->title) ? (Language::get($this->title) . ' | ') : '') . CADMIUM_NAME);
25
		}
26
27
		/**
28
		 * Output the page contents
29
		 */
30
31
		protected function _display(Template\Block $layout) {
32
33
			$view = View::get('Main/' . $this->view);
34
35
			# Set language
36
37
			$view->language = Extend\Languages::data('iso');
38
39
			# Set title
40
41
			$view->title = $this->getTitle();
42
43
			# Set layout
44
45
			$view->layout = $layout;
46
47
			# ------------------------
48
49
			Template::output($view, $this->status);
50
		}
51
52
		/**
53
		 * Output the page dynamic data as json
54
		 */
55
56
		protected function _navigate(array $layout) {
57
58
			$response = Ajax::createResponse(['navigate' => true]);
59
60
			# Set language
61
62
			$response->language = Extend\Languages::data('iso');
0 ignored issues
show
Documentation introduced by
The property language does not exist on object<Ajax\Response>. 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...
63
64
			# Set title
65
66
			$response->title = $this->getTitle();
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<Ajax\Response>. 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...
67
68
			# Set layout
69
70
			$response->layout = $layout;
0 ignored issues
show
Documentation introduced by
The property layout does not exist on object<Ajax\Response>. 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...
71
72
			# ------------------------
73
74
			Ajax::output($response);
75
		}
76
77
		/**
78
		 * Constructor
79
		 */
80
81
		public function __construct(string $title) {
82
83
			$this->title = $title;
84
		}
85
	}
86
}
87