Completed
Push — master ( ab2e37...f0a9c0 )
by Henry
13:19 queued 11:13
created

includes/Navigation/Article.php (1 issue)

call_checks.maybe_mismatching_type_passed

Bug Minor

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'))
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')));
0 ignored issues
show
It seems like $outputItem ?: $itemElem...age->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...
97
		$output .= Module\Hook::trigger('navigationArticleEnd');
98 3
		return $output;
99
	}
100
}
101