Completed
Push — master ( 14c945...6811c1 )
by Henry
05:37
created

NavigationAbstract   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 77
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A init() 0 5 1
A __toString() 0 4 1
1
<?php
2
namespace Redaxscript\Navigation;
3
4
use Redaxscript\Language;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Redaxscript\Navigation\Language.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
5
use Redaxscript\Registry;
6
use function array_replace_recursive;
7
8
/**
9
 * abstract class to create a navigation class
10
 *
11
 * @since 3.3.0
12
 *
13
 * @package Redaxscript
14
 * @category Navigation
15
 * @author Henry Ruhs
16
 */
17
18
abstract class NavigationAbstract implements NavigationInterface
19
{
20
	/**
21
	 * instance of the registry class
22
	 *
23
	 * @var Registry
24
	 */
25
26
	protected $_registry;
27
28
	/**
29
	 * instance of the language class
30
	 *
31
	 * @var Language
32
	 */
33
34
	protected $_language;
35
36
	/**
37
	 * options of the navigation
38
	 *
39
	 * @var array
40
	 */
41
42
	protected $_optionArray =
43
	[
44
		'className' =>
45
		[
46
			'list' => 'rs-list-navigation',
47
			'active' => 'rs-item-active'
48
		]
49
	];
50
51
	/**
52
	 * constructor of the class
53
	 *
54
	 * @since 3.3.0
55
	 *
56
	 * @param Registry $registry instance of the registry class
57
	 * @param Language $language instance of the language class
58
	 */
59
60
	public function __construct(Registry $registry, Language $language)
61
	{
62
		$this->_registry = $registry;
63
		$this->_language = $language;
64
	}
65
66
	/**
67
	 * init the class
68
	 *
69
	 * @since 3.3.0
70
	 *
71
	 * @param array $optionArray options of the navigation
72
	 *
73
	 * @return self
74
	 */
75
76
	public function init(array $optionArray = []) : self
77
	{
78
		$this->_optionArray = array_replace_recursive($this->_optionArray, $optionArray);
79
		return $this;
80
	}
81
82
	/**
83
	 * stringify the navigation
84
	 *
85
	 * @since 3.3.0
86
	 *
87
	 * @return string
88
	 */
89
90
	public function __toString() : string
91
	{
92
		return $this->render();
93
	}
94
}