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 article navigation |
||
11 | * |
||
12 | * @since 3.3.0 |
||
13 | * |
||
14 | * @package Redaxscript |
||
15 | * @category Navigation |
||
16 | * @author Henry Ruhs |
||
17 | */ |
||
18 | |||
19 | class Article 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-articles', |
||
32 | 'active' => 'rs-item-active' |
||
33 | ], |
||
34 | 'orderColumn' => 'rank', |
||
35 | 'limit' => null |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * render the view |
||
40 | * |
||
41 | * @since 3.3.0 |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | |||
46 | 3 | public function render() : string |
|
47 | { |
||
48 | 3 | $output = Module\Hook::trigger('navigationArticleStart'); |
|
49 | 3 | $outputItem = null; |
|
50 | 3 | $articleModel = new Model\Article(); |
|
51 | 3 | $accessValidator = new Validator\Access(); |
|
52 | |||
53 | /* html element */ |
||
54 | |||
55 | 3 | $element = new Html\Element(); |
|
56 | $listElement = $element |
||
57 | 3 | ->copy() |
|
58 | 3 | ->init('ul', |
|
59 | [ |
||
60 | 3 | 'class' => $this->_optionArray['className']['list'] |
|
61 | ]); |
||
62 | 3 | $itemElement = $element->copy()->init('li'); |
|
63 | 3 | $linkElement = $element->copy()->init('a'); |
|
64 | 3 | $textElement = $element->copy()->init('span'); |
|
65 | |||
66 | /* query articles */ |
||
67 | |||
68 | $articles = $articleModel |
||
69 | 3 | ->query() |
|
70 | 3 | ->whereLanguageIs($this->_registry->get('language')) |
|
0 ignored issues
–
show
|
|||
71 | 3 | ->where('status', 1) |
|
72 | 3 | ->orderBySetting($this->_optionArray['orderColumn']) |
|
73 | 3 | ->limit($this->_optionArray['limit']) |
|
74 | 3 | ->findMany(); |
|
75 | |||
76 | /* collect item output */ |
||
77 | |||
78 | 3 | foreach ($articles as $value) |
|
79 | { |
||
80 | 3 | if ($accessValidator->validate($value->access, $this->_registry->get('myGroups'))) |
|
0 ignored issues
–
show
It seems like
$this->_registry->get('myGroups') targeting Redaxscript\Registry::get() can also be of type array ; however, Redaxscript\Validator\Access::validate() does only seem to accept null|string , maybe add an additional type check?
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.
Loading history...
|
|||
81 | { |
||
82 | $outputItem .= $itemElement |
||
83 | 3 | ->copy() |
|
84 | 3 | ->addClass((int)$this->_registry->get('articleId') === (int)$value->id ? $this->_optionArray['className']['active'] : null) |
|
85 | 3 | ->html($linkElement |
|
86 | 3 | ->copy() |
|
87 | 3 | ->attr( |
|
88 | [ |
||
89 | 3 | 'href' => $this->_registry->get('parameterRoute') . $articleModel->getRouteById($value->id) |
|
90 | ]) |
||
91 | 3 | ->text($value->title) |
|
92 | ); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | /* collect output */ |
||
97 | |||
98 | 3 | $output .= $listElement->html($outputItem ? : $itemElement->html($textElement->text($this->_language->get('article_no')))); |
|
0 ignored issues
–
show
It seems like
$this->_language->get('article_no') targeting Redaxscript\Language::get() can also be of type array ; however, Redaxscript\Html\Element::text() does only seem to accept string|integer|null , maybe add an additional type check?
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.
Loading history...
It seems like
$outputItem ?: $itemElem...ge->get('article_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...
|
|||
99 | 3 | $output .= Module\Hook::trigger('navigationArticleEnd'); |
|
100 | 3 | return $output; |
|
101 | } |
||
102 | } |
||
103 |
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.