Completed
Push — master ( aaa756...6a04f6 )
by Henry
70:00 queued 35:28
created

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

call_checks.maybe_mismatching_type_passed_with_def

Bug Minor

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