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 | use function array_key_exists; |
||
7 | use function is_array; |
||
8 | |||
9 | /** |
||
10 | * helper class to provide a robots helper |
||
11 | * |
||
12 | * @since 3.0.0 |
||
13 | * |
||
14 | * @package Redaxscript |
||
15 | * @category Template |
||
16 | * @author Henry Ruhs |
||
17 | */ |
||
18 | |||
19 | class Robots extends HelperAbstract |
||
20 | { |
||
21 | /** |
||
22 | * array of the robots |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | |||
27 | protected static $_robotArray = |
||
28 | [ |
||
29 | 1 => 'all', |
||
30 | 2 => 'index', |
||
31 | 3 => 'follow', |
||
32 | 4 => 'index_no', |
||
33 | 5 => 'follow_no', |
||
34 | 6 => 'none' |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * process |
||
39 | * |
||
40 | * @since 3.0.0 |
||
41 | * |
||
42 | * @return string|null |
||
43 | */ |
||
44 | |||
45 | 6 | public function process() : ?string |
|
46 | { |
||
47 | 6 | $settingModel = new Model\Setting(); |
|
48 | 6 | $lastTable = $this->_registry->get('lastTable'); |
|
49 | 6 | $lastId = $this->_registry->get('lastId'); |
|
50 | 6 | $useRobots = $this->_registry->get('useRobots'); |
|
51 | 6 | $settingRobots = $settingModel->get('robots'); |
|
52 | 6 | $robots = null; |
|
53 | |||
54 | /* handle robots */ |
||
55 | |||
56 | 6 | if ($useRobots) |
|
57 | { |
||
58 | 1 | $robots = $useRobots; |
|
59 | } |
||
60 | 5 | else if ($lastTable && $lastId) |
|
61 | { |
||
62 | 3 | $content = Db::forTablePrefix($lastTable)->whereIdIs($lastId)->whereNull('access')->findOne(); |
|
0 ignored issues
–
show
|
|||
63 | 3 | $robots = $content->robots; |
|
64 | |||
65 | /* handle parent */ |
||
66 | |||
67 | 3 | if (!$robots) |
|
68 | { |
||
69 | 2 | $parentId = $content->category ? : $content->parent; |
|
70 | 2 | if ($parentId) |
|
71 | { |
||
72 | 1 | $parent = Db::forTablePrefix('categories')->whereIdIs($parentId)->whereNull('access')->findOne(); |
|
73 | 1 | $robots = $parent->robots; |
|
74 | } |
||
75 | } |
||
76 | } |
||
77 | |||
78 | /* handle robots */ |
||
79 | |||
80 | 6 | if (is_array(self::$_robotArray) && array_key_exists($robots, self::$_robotArray)) |
|
81 | { |
||
82 | 3 | return self::$_robotArray[$robots]; |
|
83 | } |
||
84 | 3 | return self::$_robotArray[$settingRobots]; |
|
85 | } |
||
86 | } |
||
87 |
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.