Completed
Push — master ( e9b1ca...cbd317 )
by Henry
07:52
created

includes/Navigation/Language.php (1 issue)

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
use function substr;
8
9
/**
10
 * children class to create the language navigation
11
 *
12
 * @since 3.3.0
13
 *
14
 * @package Redaxscript
15
 * @category Navigation
16
 * @author Henry Ruhs
17
 */
18
19
class Language 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-languages',
32
			'active' => 'rs-item-active'
33
		]
34
	];
35
36
	/**
37
	 * render the view
38
	 *
39
	 * @since 3.3.0
40
	 *
41
	 * @return string
42
	 */
43 3
44
	public function render() : string
45 3
	{
46 3
		$output = Module\Hook::trigger('navigationLanguageStart');
47
		$outputItem = null;
48
49
		/* html element */
50 3
51
		$element = new Html\Element();
52 3
		$listElement = $element
53 3
			->copy()
54
			->init('ul',
55 3
			[
56
				'class' => $this->_optionArray['className']['list']
57 3
			]);
58 3
		$itemElement = $element->copy()->init('li');
59
		$linkElement = $element->copy()->init('a');
60
61
		/* languages directory */
62 3
63 3
		$languageFilesystem = new Filesystem\Filesystem();
64 3
		$languageFilesystem->init('languages');
65
		$languageFilesystemArray = $languageFilesystem->getSortArray();
66
67
		/* collect item output */
68 3
69
		foreach ($languageFilesystemArray as $value)
70 3
		{
71
			$value = substr($value, 0, 2);
72 3
			$outputItem .= $itemElement
73 3
				->copy()
74 3
				->addClass($this->_registry->get('language') === $value ? $this->_optionArray['className']['active'] : null)
75 3
				->html($linkElement
76 3
					->copy()
77
					->attr(
78 3
					[
79 3
						'href' => $this->_registry->get('parameterRoute') . $this->_registry->get('fullRoute') . $this->_registry->get('languageRoute') . $value,
80
						'rel' => 'nofollow'
81 3
					])
82
					->text($this->_language->get($value, '_index'))
83
			);
84
		}
85
86
		/* collect output */
87 3
88
		if ($outputItem)
0 ignored issues
show
Bug Best Practice introduced by
The expression $outputItem of type null|string 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...
89 3
		{
90
			$output .= $listElement->html($outputItem);
91 3
		}
92 3
		$output .= Module\Hook::trigger('navigationLanguageEnd');
93
		return $output;
94
	}
95
}
96