Completed
Push — master ( d0c173...e44a53 )
by Henry
09:36
created

includes/View/ResultList.php (3 issues)

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\View;
3
4
use Redaxscript\Dater;
5
use Redaxscript\Html;
6
use Redaxscript\Model;
7
use Redaxscript\Module;
8
use Redaxscript\Validator;
9
10
/**
11
 * children class to create the result list
12
 *
13
 * @since 3.0.0
14
 *
15
 * @package Redaxscript
16
 * @category View
17
 * @author Henry Ruhs
18
 * @author Balázs Szilágyi
19
 */
20
21
class ResultList extends ViewAbstract
22
{
23
	/**
24
	 * render the view
25
	 *
26
	 * @since 3.0.0
27
	 *
28
	 * @param array $resultArray array for the result
29
	 *
30
	 * @return string
31
	 */
32
33 4
	public function render(array $resultArray = []) : string
34
	{
35 4
		$output = Module\Hook::trigger('resultListStart');
36 4
		$accessValidator = new Validator\Access();
37 4
		$contentModel = new Model\Content();
38 4
		$dater = new Dater();
39 4
		$parameterRoute = $this->_registry->get('parameterRoute');
40
41
		/* html element */
42
43 4
		$element = new Html\Element();
44
		$titleElement = $element
45 4
			->copy()
46 4
			->init('h2',
47
			[
48 4
				'class' => 'rs-title-result'
49
			]);
50
		$listElement = $element
51 4
			->copy()
52 4
			->init('ol',
53
			[
54 4
				'class' => 'rs-list-result'
55
			]);
56 4
		$itemElement = $element->copy()->init('li');
57
		$linkElement = $element
58 4
			->copy()
59 4
			->init('a',
60
			[
61 4
				'class' => 'rs-link-result'
62
			]);
63
		$textElement = $element
64 4
			->copy()
65 4
			->init('span',
66
			[
67 4
				'class' => 'rs-text-result-date'
68
			]);
69
70
		/* process results */
71
72 4
		foreach ($resultArray as $table => $result)
73
		{
74 4
			$outputItem = null;
75 4
			if ($result)
76
			{
77
				/* collect item output */
78
79 4
				foreach ($result as $value)
80
				{
81 4
					if ($accessValidator->validate($result->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...
82
					{
83 4
						$dater->init($value->date);
84
						$linkElement
85 4
							->attr('href', $parameterRoute . $contentModel->getRouteByTableAndId($table, $value->id))
86 4
							->text($value->title ? : $value->author);
87 4
						$textElement->text($dater->formatDate());
88 4
						$outputItem .= $itemElement->html($linkElement . $textElement);
89
					}
90
				}
91
92
				/* collect output */
93
94 4
				if ($outputItem)
0 ignored issues
show
Bug Best Practice introduced by
The expression $outputItem of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
95
				{
96 4
					$titleElement->text($this->_language->get($table));
0 ignored issues
show
It seems like $this->_language->get($table) 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...
97 4
					$listElement->html($outputItem);
98 4
					$output .= $titleElement . $listElement;
99
				}
100
			}
101
		}
102 4
		$output .= Module\Hook::trigger('resultListEnd');
103 4
		return $output;
104
	}
105
}
106