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

includes/Template/Helper/Title.php (4 issues)

call_checks.maybe_mismatching_type_passed_with_def

Bug Minor

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\Template\Helper;
3
4
use Redaxscript\Db;
5
use Redaxscript\Model;
6
7
/**
8
 * helper class to provide a title helper
9
 *
10
 * @since 3.0.0
11
 *
12
 * @package Redaxscript
13
 * @category Template
14
 * @author Henry Ruhs
15
 */
16
17
class Title extends HelperAbstract
18
{
19
	/**
20
	 * process
21
	 *
22
	 * @since 3.0.0
23
	 *
24
	 * @return string|null
25
	 */
26
27 18
	public function process() : ?string
28
	{
29 18
		$settingModel = new Model\Setting();
30 18
		$firstParameter = $this->_registry->get('firstParameter');
31 18
		$secondParameter = $this->_registry->get('secondParameter');
32 18
		$adminParameter = $this->_registry->get('adminParameter');
33 18
		$tableParameter = $this->_registry->get('tableParameter');
34 18
		$lastTable = $this->_registry->get('lastTable');
35 18
		$lastId = $this->_registry->get('lastId');
36 18
		$useTitle = $this->_registry->get('useTitle');
37 18
		$settingDivider = $settingModel->get('divider');
38 18
		$settingTitle = $settingModel->get('title');
39 18
		$title = null;
40
41
		/* find title */
42
43 18
		if ($useTitle)
44
		{
45 1
			$title = $useTitle;
46
		}
47
48
		/* handle admin */
49
50 17
		else if ($firstParameter === 'admin')
51
		{
52 3
			$title = $this->_language->get('administration');
53 3
			if ($adminParameter && $this->_language->get($adminParameter))
0 ignored issues
show
It seems like $adminParameter defined by $this->_registry->get('adminParameter') on line 32 can also be of type array; however, Redaxscript\Registry::get() 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...
54
			{
55 2
				$title .= $settingDivider . $this->_language->get($adminParameter);
0 ignored issues
show
It seems like $adminParameter defined by $this->_registry->get('adminParameter') on line 32 can also be of type array; however, Redaxscript\Registry::get() 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...
56 2
				if ($tableParameter && $this->_language->get($tableParameter))
0 ignored issues
show
It seems like $tableParameter defined by $this->_registry->get('tableParameter') on line 33 can also be of type array; however, Redaxscript\Registry::get() 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...
57
				{
58 3
					$title .= $settingDivider . $this->_language->get($tableParameter);
0 ignored issues
show
It seems like $tableParameter defined by $this->_registry->get('tableParameter') on line 33 can also be of type array; however, Redaxscript\Registry::get() 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...
59
				}
60
			}
61
		}
62
63
		/* handle login */
64
65 14
		else if ($firstParameter === 'login')
66
		{
67 3
			if ($secondParameter === 'recover')
68
			{
69 1
				$title = $this->_language->get('recovery');
70
			}
71 2
			else if ($secondParameter === 'reset')
72
			{
73 1
				$title = $this->_language->get('reset');
74
			}
75
			else
76
			{
77 3
				$title = $this->_language->get('login');
78
			}
79
		}
80
81
		/* handle logout */
82
83 11
		else if ($firstParameter === 'logout')
84
		{
85 1
			$title = $this->_language->get('logout');
86
		}
87
88
		/* handle register */
89
90 10
		else if ($firstParameter === 'register')
91
		{
92 1
			$title = $this->_language->get('registration');
93
		}
94
95
		/* handle module */
96
97 9
		else if ($firstParameter === 'module')
98
		{
99 1
			$title = $this->_language->get('module');
100
		}
101
102
		/* handle search */
103
104 8
		else if ($firstParameter === 'search')
105
		{
106 1
			$title = $this->_language->get('search');
107
		}
108
109
		/* handle error */
110
111 7
		else if (!$lastId)
112
		{
113 2
			$title = $this->_language->get('error');
114
		}
115 5
		else if ($lastTable && $lastId)
116
		{
117 5
			$title = Db::forTablePrefix($lastTable)->whereIdIs($lastId)->whereNull('access')->findOne()->title;
118
		}
119
120
		/* handle title */
121
122 18
		if ($title && $settingTitle)
123
		{
124 17
			return $title . $settingDivider . $settingTitle;
125
		}
126 1
		return $title ? : $settingTitle;
127
	}
128
}
129