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\Html; |
||
5 | use Redaxscript\Model; |
||
6 | use Redaxscript\Module; |
||
7 | use Redaxscript\Validator; |
||
8 | |||
9 | /** |
||
10 | * children class to create the category navigation |
||
11 | * |
||
12 | * @since 3.3.0 |
||
13 | * |
||
14 | * @package Redaxscript |
||
15 | * @category Navigation |
||
16 | * @author Henry Ruhs |
||
17 | */ |
||
18 | |||
19 | class Category 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-categories', |
||
32 | 'children' => 'rs-list-children', |
||
33 | 'active' => 'rs-item-active' |
||
34 | ], |
||
35 | 'orderColumn' => 'rank', |
||
36 | 'parentId' => 0 |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * render the view |
||
41 | * |
||
42 | * @since 3.3.0 |
||
43 | * |
||
44 | * @return string |
||
45 | */ |
||
46 | |||
47 | 4 | public function render() : string |
|
48 | { |
||
49 | 4 | $output = Module\Hook::trigger('navigationCategoryStart'); |
|
50 | 4 | $categoryModel = new Model\Category(); |
|
51 | |||
52 | /* query categories */ |
||
53 | |||
54 | $categories = $categoryModel |
||
55 | 4 | ->query() |
|
56 | 4 | ->whereLanguageIs($this->_registry->get('language')) |
|
0 ignored issues
–
show
|
|||
57 | 4 | ->where('status', 1) |
|
58 | 4 | ->orderBySetting($this->_optionArray['orderColumn']) |
|
59 | 4 | ->limit($this->_optionArray['limit']) |
|
60 | 4 | ->findMany(); |
|
61 | |||
62 | /* collect output */ |
||
63 | |||
64 | 4 | $output .= $this->renderList($categories, $this->_optionArray); |
|
65 | 4 | $output .= Module\Hook::trigger('navigationCategoryEnd'); |
|
66 | 4 | return $output; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * render the list |
||
71 | * |
||
72 | * @since 3.3.0 |
||
73 | * |
||
74 | * @param object $categories |
||
75 | * @param array $optionArray |
||
76 | * |
||
77 | * @return string|null |
||
78 | */ |
||
79 | |||
80 | 4 | protected function renderList(object $categories = null, array $optionArray = []) : ?string |
|
81 | { |
||
82 | 4 | $output = null; |
|
83 | 4 | $outputItem = null; |
|
84 | 4 | $categoryModel = new Model\Category(); |
|
85 | 4 | $accessValidator = new Validator\Access(); |
|
86 | |||
87 | /* html element */ |
||
88 | |||
89 | 4 | $element = new Html\Element(); |
|
90 | $listElement = $element |
||
91 | 4 | ->copy() |
|
92 | 4 | ->init('ul', |
|
93 | [ |
||
94 | 4 | 'class' => $optionArray['className']['list'] |
|
95 | ]); |
||
96 | 4 | $itemElement = $element->copy()->init('li'); |
|
97 | 4 | $linkElement = $element->copy()->init('a'); |
|
98 | |||
99 | /* collect item output */ |
||
100 | |||
101 | 4 | foreach ($categories as $value) |
|
102 | { |
||
103 | 4 | if ($accessValidator->validate($value->access, $this->_registry->get('myGroups')) && $optionArray['parentId'] === (int)$value->parent) |
|
104 | { |
||
105 | $outputItem .= $itemElement |
||
106 | 4 | ->copy() |
|
107 | 4 | ->addClass((int)$this->_registry->get('categoryId') === (int)$value->id ? $this->_optionArray['className']['active'] : null) |
|
108 | 4 | ->html($linkElement |
|
109 | 4 | ->copy() |
|
110 | 4 | ->attr( |
|
111 | [ |
||
112 | 4 | 'href' => $this->_registry->get('parameterRoute') . $categoryModel->getRouteById($value->id) |
|
113 | ]) |
||
114 | 4 | ->text($value->title) |
|
115 | ) |
||
116 | 4 | ->append( |
|
117 | 4 | $this->renderList($categories, |
|
118 | [ |
||
119 | 'className' => |
||
120 | [ |
||
121 | 4 | 'list' => $value->parent ? $optionArray['className']['list'] : $optionArray['className']['children'], |
|
122 | 4 | 'active' => $optionArray['className']['active'], |
|
123 | ], |
||
124 | 4 | 'parentId' => (int)$value->id |
|
125 | ]) |
||
126 | ); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | /* collect output */ |
||
131 | |||
132 | 4 | if ($outputItem) |
|
133 | { |
||
134 | 4 | $output .= $listElement->html($outputItem); |
|
135 | } |
||
136 | 4 | else if (!$categories->count()) |
|
137 | { |
||
138 | $output .= $listElement->html( |
||
139 | $itemElement->text($this->_language->get('category_no')) |
||
140 | ); |
||
141 | } |
||
142 | return $output; |
||
143 | } |
||
144 | } |
||
145 |
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.