Completed
Push — master ( 0ea243...da58d4 )
by Henry
10:25 queued 33s
created

includes/Router/Resolver.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\Router;
3
4
use function array_diff;
5
use function implode;
6
use function in_array;
7
8
/**
9
 * children class to resolve a route
10
 *
11
 * @since 3.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Router
15
 * @author Henry Ruhs
16
 */
17
18
class Resolver extends Parameter
19
{
20
	/**
21
	 * array of the resolver
22
	 *
23
	 * @var array
24
	 */
25
26
	protected $_resolverArray =
27
	[
28
		'view' =>
29
		[
30
			'enable',
31
			'disabled',
32
			'publish',
33
			'unpublish',
34
			'install',
35
			'uninstall',
36
			'delete'
37
		]
38
	];
39
40
	/**
41
	 * get the lite route
42
	 *
43
	 * @since 2.4.0
44
	 *
45
	 * @return string|null
46
	 */
47
48 17
	public function getLite() : ?string
49
	{
50 17
		return $this->_getRoute('lite');
51
	}
52
53
	/**
54
	 * get the full route
55
	 *
56
	 * @since 2.4.0
57
	 *
58
	 * @return string|null
59
	 */
60
61 17
	public function getFull() : ?string
62
	{
63 17
		return $this->_getRoute('full');
64
	}
65
66
	/**
67
	 * get the route
68
	 *
69
	 * @since 2.4.0
70
	 *
71
	 * @param string $type type of the route
72
	 *
73
	 * @return string|null
74
	 */
75
76 34
	protected function _getRoute(string $type = null) : ?string
77
	{
78 34
		$output = null;
79 34
		$adminParameter = $this->getAdmin();
80 34
		$tableParameter = $this->getTable();
81
		$subArray =
82
		[
83 34
			$this->getLastSub()
84
		];
85
86
		/* admin route */
87
88 34
		if (in_array($adminParameter, $this->_resolverArray['view']))
89
		{
90 6
			$output = 'admin/view/' . $tableParameter;
91
		}
92
93
		/* else general route */
94
95 28
		else if ($this->_parameterArray)
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_parameterArray of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
96
		{
97 26
			if ($type === 'lite')
98
			{
99 13
				$output = implode('/', array_diff($this->_parameterArray, $subArray));
100
			}
101 13
			else if ($type === 'full')
102
			{
103 13
				$output = implode('/', $this->_parameterArray);
104
			}
105
		}
106 34
		return $output;
107
	}
108
}