Completed
Push — master ( 14c945...6811c1 )
by Henry
05:37
created

Keywords   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 48
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 37 8
1
<?php
2
namespace Redaxscript\Template\Helper;
3
4
use Redaxscript\Db;
5
use Redaxscript\Model;
6
7
/**
8
 * helper class to provide a keywords helper
9
 *
10
 * @since 3.0.0
11
 *
12
 * @package Redaxscript
13
 * @category Template
14
 * @author Henry Ruhs
15
 */
16
17
class Keywords extends HelperAbstract
18
{
19
	/**
20
	 * process
21
	 *
22
	 * @since 3.0.0
23
	 *
24
	 * @return string|null
25
	 */
26
27
	public function process() : ?string
28
	{
29
		$settingModel = new Model\Setting();
30
		$lastTable = $this->_registry->get('lastTable');
31
		$lastId = $this->_registry->get('lastId');
32
		$useKeywords = $this->_registry->get('useKeywords');
33
		$settingKeywords = $settingModel->get('keywords');
34
		$keywords = null;
35
36
		/* find keywords */
37
38
		if ($useKeywords)
39
		{
40
			$keywords = $useKeywords;
41
		}
42
		else if ($lastTable && $lastId)
43
		{
44
			$content = Db::forTablePrefix($lastTable)->whereIdIs($lastId)->whereNull('access')->findOne();
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $lastTable defined by $this->_registry->get('lastTable') on line 30 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...
45
			$keywords = $content->keywords;
46
47
			/* handle parent */
48
49
			if (!$keywords)
50
			{
51
				$parentId = $content->category ? : $content->parent;
52
				if ($parentId)
53
				{
54
					$parent = Db::forTablePrefix('categories')->whereIdIs($parentId)->whereNull('access')->findOne();
55
					$keywords = $parent->keywords;
56
				}
57
			}
58
		}
59
60
		/* handle keywords */
61
62
		return $keywords ? : $settingKeywords;
63
	}
64
}
65