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 description helper |
||
9 | * |
||
10 | * @since 3.0.0 |
||
11 | * |
||
12 | * @package Redaxscript |
||
13 | * @category Template |
||
14 | * @author Henry Ruhs |
||
15 | */ |
||
16 | |||
17 | class Description 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 | $useDescription = $this->_registry->get('useDescription'); |
|
33 | 8 | $settingDescription = $settingModel->get('description'); |
|
34 | 8 | $description = null; |
|
35 | |||
36 | /* find description */ |
||
37 | |||
38 | 8 | if ($useDescription) |
|
39 | { |
||
40 | 1 | $description = $useDescription; |
|
41 | } |
||
42 | 7 | else if ($lastTable && $lastId) |
|
43 | { |
||
44 | 5 | $content = Db::forTablePrefix($lastTable)->whereIdIs($lastId)->whereNull('access')->findOne(); |
|
0 ignored issues
–
show
|
|||
45 | 5 | $description = $content->description; |
|
46 | |||
47 | /* handle parent */ |
||
48 | |||
49 | 5 | if (!$description) |
|
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 | $description = $parent->description; |
|
56 | } |
||
57 | } |
||
58 | } |
||
59 | |||
60 | /* handle description */ |
||
61 | |||
62 | 8 | return $description ? : $settingDescription; |
|
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.