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 | public function process() : ?string |
||
46 | { |
||
47 | $settingModel = new Model\Setting(); |
||
48 | $lastTable = $this->_registry->get('lastTable'); |
||
49 | $lastId = $this->_registry->get('lastId'); |
||
50 | $useRobots = $this->_registry->get('useRobots'); |
||
51 | $settingRobots = $settingModel->get('robots'); |
||
52 | $robots = null; |
||
53 | |||
54 | /* handle robots */ |
||
55 | |||
56 | if ($useRobots) |
||
57 | { |
||
58 | $robots = $useRobots; |
||
59 | } |
||
60 | else if ($lastTable && $lastId) |
||
61 | { |
||
62 | $content = Db::forTablePrefix($lastTable)->whereIdIs($lastId)->whereNull('access')->findOne(); |
||
0 ignored issues
–
show
|
|||
63 | $robots = $content->robots; |
||
64 | |||
65 | /* handle parent */ |
||
66 | |||
67 | if (!$robots) |
||
68 | { |
||
69 | $parentId = $content->category ? : $content->parent; |
||
70 | if ($parentId) |
||
71 | { |
||
72 | $parent = Db::forTablePrefix('categories')->whereIdIs($parentId)->whereNull('access')->findOne(); |
||
73 | $robots = $parent->robots; |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 | |||
78 | /* handle robots */ |
||
79 | |||
80 | if (is_array(self::$_robotArray) && array_key_exists($robots, self::$_robotArray)) |
||
81 | { |
||
82 | return self::$_robotArray[$robots]; |
||
83 | } |
||
84 | 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.