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 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
|
|||
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 |
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:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.