Completed
Push — develop ( 9e183f...0abb5c )
by Daniel
08:58
created

menu   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 41
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get_config() 0 12 1
A get_depth_options() 0 10 2
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2013 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\blocks;
11
12
/**
13
* Menu Block
14
* @package phpBB Sitemaker Main Menu
15
*/
16
class menu extends links
17
{
18
	/** @var string */
19
	protected $title = 'MENU';
20
21
	/** @var string */
22
	protected $tpl_name = 'menu';
23
24
	/** @var bool */
25
	protected $is_navigation = true;
26
27
	/**
28
	 * {@inheritdoc}
29
	 */
30 1
	public function get_config(array $settings)
31
	{
32 1
		$menu_options = $this->navigation->get_menu_options();
33 1
		$depth_options = $this->get_depth_options();
34
35
		return array(
0 ignored issues
show
Best Practice introduced by
The expression return array('legend1' =..., 'explain' => false)); seems to be an array, but some of its elements' types (array) are incompatible with the return type of the parent method blitze\sitemaker\blocks\links::get_config of type array<string,string|arra...tring[]|integer|false>>.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
36 1
			'legend1'       => 'SETTINGS',
37 1
			'menu_id'		=> array('lang' => 'MENU', 'validate' => 'int', 'type' => 'select', 'options' => $menu_options, 'default' => 0, 'explain' => false),
38 1
			'expanded'		=> array('lang' => 'EXPANDED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'default' => 0, 'explain' => false),
39 1
			'max_depth'		=> array('lang' => 'MAX_DEPTH', 'validate' => 'int', 'type' => 'select', 'options' => $depth_options, 'default' => 3, 'explain' => false),
40 1
		);
41
	}
42
43
	/**
44
	 * @return int[]
45
	 */
46 1
	protected function get_depth_options()
47
	{
48 1
		$options = array();
49 1
		for ($i = 3; $i < 10; $i++)
50
		{
51 1
			$options[$i] = $i;
52 1
		}
53
54 1
		return $options;
55
	}
56
}
57