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 | 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 | |||
35 | /* find keywords */ |
||
36 | |||
37 | 8 | if ($useKeywords) |
|
38 | { |
||
39 | 1 | $keywords = $useKeywords; |
|
40 | } |
||
41 | 7 | else if ($lastTable && $lastId) |
|
42 | { |
||
43 | 5 | $content = Db::forTablePrefix($lastTable)->whereIdIs($lastId)->whereNull('access')->findOne(); |
|
44 | 5 | $keywords = $content->keywords; |
|
45 | |||
46 | /* handle parent */ |
||
47 | |||
48 | 5 | if (!$keywords) |
|
49 | { |
||
50 | 3 | $parentId = $content->category ? : $content->parent; |
|
51 | 3 | if ($parentId) |
|
52 | { |
||
53 | 2 | $parent = Db::forTablePrefix('categories')->whereIdIs($parentId)->whereNull('access')->findOne(); |
|
54 | 2 | $keywords = $parent->keywords; |
|
55 | } |
||
56 | } |
||
57 | } |
||
58 | |||
59 | /* handle keywords */ |
||
60 | |||
61 | 8 | if ($keywords) |
|
62 | { |
||
63 | 5 | return $keywords; |
|
0 ignored issues
–
show
|
|||
64 | } |
||
65 | 3 | return $settingKeywords; |
|
66 | } |
||
67 | } |
||
68 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: