Completed
Push — master ( cbd317...231b94 )
by Henry
09:43
created

includes/Template/Helper/Robots.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

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 6
	 */
44
45 6
	public function process() : ?string
46 6
	{
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
		$settingRobots = $settingModel->get('robots');
52
		$robots = null;
53
54 6
		/* handle robots */
55
56 1
		if ($useRobots)
57
		{
58 5
			$robots = $useRobots;
59
		}
60 3
		else if ($lastTable && $lastId)
61 3
		{
62
			$content = Db::forTablePrefix($lastTable)->whereIdIs($lastId)->whereNull('access')->findOne();
0 ignored issues
show
It seems like $lastTable defined by $this->_registry->get('lastTable') on line 48 can also be of type array; however, Redaxscript\Db::forTablePrefix() does only seem to accept null|string, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
63
			$robots = $content->robots;
64
65 3
			/* handle parent */
66
67 2
			if (!$robots)
68 2
			{
69
				$parentId = $content->category ? : $content->parent;
70 1
				if ($parentId)
71 1
				{
72
					$parent = Db::forTablePrefix('categories')->whereIdIs($parentId)->whereNull('access')->findOne();
73
					$robots = $parent->robots;
74
				}
75
			}
76
		}
77
78 6
		/* handle robots */
79
80 3
		if (is_array(self::$_robotArray) && array_key_exists($robots, self::$_robotArray))
81
		{
82 3
			return self::$_robotArray[$robots];
83
		}
84
		return self::$_robotArray[$settingRobots];
85
	}
86
}
87