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
|
|||
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 | } |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/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 beforeOtherDir/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: