Completed
Push — master ( 14c945...6811c1 )
by Henry
05:37
created

Article   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 8
dl 0
loc 83
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B render() 0 56 5
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
	public function render() : string
46
	{
47
		$output = Module\Hook::trigger('navigationArticleStart');
48
		$outputItem = null;
49
		$articleModel = new Model\Article();
50
		$accessValidator = new Validator\Access();
51
52
		/* html element */
53
54
		$element = new Html\Element();
55
		$listElement = $element
56
			->copy()
57
			->init('ul',
58
			[
59
				'class' => $this->_optionArray['className']['list']
60
			]);
61
		$itemElement = $element->copy()->init('li');
62
		$linkElement = $element->copy()->init('a');
63
		$textElement = $element->copy()->init('span');
64
65
		/* query articles */
66
67
		$articles = $articleModel
68
			->query()
69
			->whereLanguageIs($this->_registry->get('language'))
0 ignored issues
show
Bug introduced by
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...
70
			->where('status', 1)
71
			->orderBySetting($this->_optionArray['orderColumn'])
72
			->limit($this->_optionArray['limit'])
73
			->findMany();
74
75
		/* collect item output */
76
77
		foreach ($articles as $value)
78
		{
79
			if ($accessValidator->validate($value->access, $this->_registry->get('myGroups')))
0 ignored issues
show
Bug introduced by
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...
80
			{
81
				$outputItem .= $itemElement
82
					->copy()
83
					->addClass((int)$this->_registry->get('articleId') === (int)$value->id ? $this->_optionArray['className']['active'] : null)
84
					->html($linkElement
85
						->copy()
86
						->attr(
87
						[
88
							'href' => $this->_registry->get('parameterRoute') . $articleModel->getRouteById($value->id)
89
						])
90
						->text($value->title)
91
					);
92
			}
93
		}
94
95
		/* collect output */
96
97
		$output .= $listElement->html($outputItem ? : $itemElement->html($textElement->text($this->_language->get('article_no'))));
0 ignored issues
show
Bug introduced by
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...
Bug introduced by
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...
98
		$output .= Module\Hook::trigger('navigationArticleEnd');
99
		return $output;
100
	}
101
}
102