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

includes/Navigation/Template.php (2 issues)

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\Filesystem;
5
use Redaxscript\Html;
6
use Redaxscript\Module;
7
8
/**
9
 * children class to create the language navigation
10
 *
11
 * @since 3.3.0
12
 *
13
 * @package Redaxscript
14
 * @category Navigation
15
 * @author Henry Ruhs
16
 */
17
18
class Template extends NavigationAbstract
19
{
20
	/**
21
	 * options of the navigation
22
	 *
23
	 * @var array
24
	 */
25
26
	protected $_optionArray =
27
	[
28
		'className' =>
29
		[
30
			'list' => 'rs-list-templates',
31
			'active' => 'rs-item-active'
32
		]
33
	];
34
35
	/**
36
	 * render the view
37
	 *
38
	 * @since 3.3.0
39
	 *
40
	 * @return string
41
	 */
42
43 3
	public function render() : string
44
	{
45 3
		$output = Module\Hook::trigger('navigationTemplateStart');
46 3
		$outputItem = null;
47
48
		/* html element */
49
50 3
		$element = new Html\Element();
51
		$listElement = $element
52 3
			->copy()
53 3
			->init('ul',
54
			[
55 3
				'class' => $this->_optionArray['className']['list']
56
			]);
57 3
		$itemElement = $element->copy()->init('li');
58 3
		$linkElement = $element->copy()->init('a');
59
60
		/* template directory */
61
62 3
		$templateFilesystem = new Filesystem\Filesystem();
63 3
		$templateFilesystem->init('templates', false,
64
		[
65 3
			'admin',
66
			'console',
67
			'install'
68
		]);
69 3
		$templateFilesystemArray = $templateFilesystem->getSortArray();
70
71
		/* collect item output */
72
73 3
		foreach ($templateFilesystemArray as $value)
74
		{
75
			$outputItem .= $itemElement
76 3
				->copy()
77 3
				->addClass($this->_registry->get('template') === $value ? $this->_optionArray['className']['active'] : null)
78 3
				->html($linkElement
79 3
					->copy()
80 3
					->attr(
81
					[
82 3
						'href' => $this->_registry->get('parameterRoute') . $this->_registry->get('fullRoute') . $this->_registry->get('templateRoute') . $value,
83 3
						'rel' => 'nofollow'
84
					])
85 3
					->text($value)
86
				);
87
		}
88
89
		/* collect output */
90
91 3
		$output .= $listElement->html($outputItem ? : $itemElement->text($this->_language->get('template_no')));
0 ignored issues
show
It seems like $this->_language->get('template_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('template_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...
92
		$output .= Module\Hook::trigger('navigationTemplateEnd');
93 3
		return $output;
94
	}
95
}
96