Keywords::process()   B
last analyzed

Complexity

Conditions 8
Paths 14

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 8

Importance

Changes 0
Metric Value
dl 0
loc 37
c 0
b 0
f 0
ccs 18
cts 18
cp 1
rs 8.0835
cc 8
nc 14
nop 0
crap 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