Completed
Push — master ( a52438...bf8826 )
by Henry
06:30
created

includes/Navigation/NavigationAbstract.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript\Navigation;
3
4
use Redaxscript\Language;
0 ignored issues
show
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 14
	public function __construct(Registry $registry, Language $language)
61
	{
62 14
		$this->_registry = $registry;
63 14
		$this->_language = $language;
64 14
	}
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 14
	public function init(array $optionArray = []) : self
77
	{
78 14
		$this->_optionArray = array_replace_recursive($this->_optionArray, $optionArray);
79 14
		return $this;
80
	}
81
82
	/**
83
	 * stringify the navigation
84
	 *
85
	 * @since 3.3.0
86
	 *
87
	 * @return string
88
	 */
89
90 14
	public function __toString() : string
91
	{
92 14
		return $this->render();
93
	}
94
}