Keywords   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 0
loc 48
ccs 18
cts 18
cp 1
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 8
	public function process() : ?string
28
	{
29 8
		$settingModel = new Model\Setting();
30 8
		$lastTable = $this->_registry->get('lastTable');
31 8
		$lastId = $this->_registry->get('lastId');
32 8
		$useKeywords = $this->_registry->get('useKeywords');
33 8
		$settingKeywords = $settingModel->get('keywords');
34 8
		$keywords = null;
35
36
		/* find keywords */
37
38 8
		if ($useKeywords)
39
		{
40 1
			$keywords = $useKeywords;
41
		}
42 7
		else if ($lastTable && $lastId)
43
		{
44 5
			$content = Db::forTablePrefix($lastTable)->whereIdIs($lastId)->whereNull('access')->findOne();
45 5
			$keywords = $content->keywords;
46
47
			/* handle parent */
48
49 5
			if (!$keywords)
50
			{
51 3
				$parentId = $content->category ? : $content->parent;
52 3
				if ($parentId)
53
				{
54 2
					$parent = Db::forTablePrefix('categories')->whereIdIs($parentId)->whereNull('access')->findOne();
55 2
					$keywords = $parent->keywords;
56
				}
57
			}
58
		}
59
60
		/* handle keywords */
61
62 8
		return $keywords ? : $settingKeywords;
63
	}
64
}
65