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\Filesystem; |
||
5 | use Redaxscript\Html; |
||
6 | use Redaxscript\Module; |
||
7 | use function substr; |
||
8 | |||
9 | /** |
||
10 | * children class to create the language navigation |
||
11 | * |
||
12 | * @since 3.3.0 |
||
13 | * |
||
14 | * @package Redaxscript |
||
15 | * @category Navigation |
||
16 | * @author Henry Ruhs |
||
17 | */ |
||
18 | |||
19 | class Language extends NavigationAbstract |
||
20 | { |
||
21 | /** |
||
22 | * options of the navigation |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | |||
27 | protected $_optionArray = |
||
28 | [ |
||
29 | 'className' => |
||
30 | [ |
||
31 | 'list' => 'rs-list-languages', |
||
32 | 'active' => 'rs-item-active' |
||
33 | ] |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * render the view |
||
38 | * |
||
39 | * @since 3.3.0 |
||
40 | * |
||
41 | * @return string |
||
42 | */ |
||
43 | 3 | ||
44 | public function render() : string |
||
45 | 3 | { |
|
46 | 3 | $output = Module\Hook::trigger('navigationLanguageStart'); |
|
47 | $outputItem = null; |
||
48 | |||
49 | /* html element */ |
||
50 | 3 | ||
51 | $element = new Html\Element(); |
||
52 | 3 | $listElement = $element |
|
53 | 3 | ->copy() |
|
54 | ->init('ul', |
||
55 | 3 | [ |
|
56 | 'class' => $this->_optionArray['className']['list'] |
||
57 | 3 | ]); |
|
58 | 3 | $itemElement = $element->copy()->init('li'); |
|
59 | $linkElement = $element->copy()->init('a'); |
||
60 | |||
61 | /* languages directory */ |
||
62 | 3 | ||
63 | 3 | $languageFilesystem = new Filesystem\Filesystem(); |
|
64 | 3 | $languageFilesystem->init('languages'); |
|
65 | $languageFilesystemArray = $languageFilesystem->getSortArray(); |
||
66 | |||
67 | /* collect item output */ |
||
68 | 3 | ||
69 | foreach ($languageFilesystemArray as $value) |
||
70 | 3 | { |
|
71 | $value = substr($value, 0, 2); |
||
72 | 3 | $outputItem .= $itemElement |
|
73 | 3 | ->copy() |
|
74 | 3 | ->addClass($this->_registry->get('language') === $value ? $this->_optionArray['className']['active'] : null) |
|
75 | 3 | ->html($linkElement |
|
76 | 3 | ->copy() |
|
77 | ->attr( |
||
78 | 3 | [ |
|
79 | 3 | 'href' => $this->_registry->get('parameterRoute') . $this->_registry->get('fullRoute') . $this->_registry->get('languageRoute') . $value, |
|
80 | 'rel' => 'nofollow' |
||
81 | 3 | ]) |
|
82 | ->text($this->_language->get($value, '_index')) |
||
83 | ); |
||
84 | } |
||
85 | |||
86 | /* collect output */ |
||
87 | 3 | ||
88 | $output .= $listElement->html($outputItem ? : $itemElement->text($this->_language->get('language_no'))); |
||
0 ignored issues
–
show
It seems like
$outputItem ?: $itemElem...ge->get('language_no')) can also be of type object<Redaxscript\Html\Element> ; however, Redaxscript\Html\HtmlAbstract::html() does only seem to accept null|string , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
89 | 3 | $output .= Module\Hook::trigger('navigationLanguageEnd'); |
|
90 | return $output; |
||
91 | 3 | } |
|
92 | } |
||
93 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.