Completed
Push — master ( c3c208...858dca )
by Henry
08:18
created

Title   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 4
dl 0
loc 112
c 0
b 0
f 0
ccs 41
cts 41
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
F process() 0 101 20
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
Bug introduced by
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
Bug introduced by
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
Bug introduced by
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
Bug introduced by
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;
0 ignored issues
show
Bug introduced by
It seems like $lastTable defined by $this->_registry->get('lastTable') on line 34 can also be of type array; however, Redaxscript\Db::forTablePrefix() 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...
118
		}
119
120
		/* handle title */
121
122 18
		if ($title && $settingTitle)
0 ignored issues
show
Bug Best Practice introduced by
The expression $settingTitle 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...
123
		{
124 17
			return $title . $settingDivider . $settingTitle;
125
		}
126 1
		return $title ? : $settingTitle;
127
	}
128
}
129