Completed
Push — master ( 1da492...320203 )
by Henry
07:00
created

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

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 description helper
9
 *
10
 * @since 3.0.0
11
 *
12
 * @package Redaxscript
13
 * @category Template
14
 * @author Henry Ruhs
15
 */
16
17
class Description extends HelperAbstract
18
{
19
	/**
20
	 * process
21
	 *
22
	 * @since 3.0.0
23
	 *
24
	 * @return string|null
25
	 */
26
27
	public function process() : ?string
28
	{
29
		$settingModel = new Model\Setting();
30
		$lastTable = $this->_registry->get('lastTable');
31
		$lastId = $this->_registry->get('lastId');
32
		$useDescription = $this->_registry->get('useDescription');
33
		$settingDescription = $settingModel->get('description');
34
		$description = null;
35
36
		/* find description */
37
38
		if ($useDescription)
39
		{
40
			$description = $useDescription;
41
		}
42
		else if ($lastTable && $lastId)
43
		{
44
			$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 30 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...
45
			$description = $content->description;
46
47
			/* handle parent */
48
49
			if (!$description)
50
			{
51
				$parentId = $content->category ? : $content->parent;
52
				if ($parentId)
53
				{
54
					$parent = Db::forTablePrefix('categories')->whereIdIs($parentId)->whereNull('access')->findOne();
55
					$description = $parent->description;
56
				}
57
			}
58
		}
59
60
		/* handle description */
61
62
		return $description ? : $settingDescription;
63
	}
64
}
65