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

includes/Detector/Language.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\Detector;
3
4
use Redaxscript\Db;
5
use Redaxscript\Model;
6
7
/**
8
 * children class to detect the required language
9
 *
10
 * @since 2.0.0
11
 *
12
 * @package Redaxscript
13
 * @category Detector
14
 * @author Henry Ruhs
15
 */
16
17
class Language extends DetectorAbstract
18
{
19
	/**
20
	 * automate run
21
	 *
22
	 * @since 2.1.0
23
	 */
24
25 8
	protected function _autorun()
26
	{
27 8
		$settingModel = new Model\Setting();
28 8
		$dbStatus = $this->_registry->get('dbStatus');
29 8
		$lastTable = $this->_registry->get('lastTable');
30 8
		$lastId = $this->_registry->get('lastId');
31
32
		/* detect language */
33
34 8
		$this->_output = $this->_detect(
35
		[
36 8
			'query' => $this->_request->getQuery('l'),
37 8
			'session' => $this->_request->getSession('language'),
38 8
			'contents' => $lastTable ? Db::forTablePrefix($lastTable)->whereIdIs($lastId)->findOne()->language : null,
0 ignored issues
show
It seems like $lastTable defined by $this->_registry->get('lastTable') on line 29 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...
39 8
			'settings' => $dbStatus === 2 ? $settingModel->get('language') : null,
40 8
			'browser' => substr($this->_request->getServer('HTTP_ACCEPT_LANGUAGE'), 0, 2),
41 8
			'fallback' => 'en'
42 8
		], 'language', 'languages' . DIRECTORY_SEPARATOR . $this->_filePlaceholder . '.json');
43 8
	}
44
}
45