Completed
Push — master ( 8809d0...5c8ee8 )
by Henry
06:08
created

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