Completed
Push — master ( e9cd30...c2303d )
by Henry
05:05
created

includes/Detector/Language.php (2 issues)

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\Detector;
3
4
use Redaxscript\Filter;
5
use Redaxscript\Model;
6
use function substr;
7
8
/**
9
 * children class to detect the current language
10
 *
11
 * @since 2.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Detector
15
 * @author Henry Ruhs
16
 */
17
18
class Language extends DetectorAbstract
19
{
20
	/**
21
	 * automate run
22
	 *
23
	 * @since 2.1.0
24
	 */
25
26 8
	public function autorun() : void
27
	{
28 8
		$settingModel = new Model\Setting();
29 8
		$contentModel = new Model\Content();
30 8
		$specialFilter = new Filter\Special();
31 8
		$dbStatus = $this->_registry->get('dbStatus');
32 8
		$lastTable = $this->_registry->get('lastTable');
33 8
		$lastId = $this->_registry->get('lastId');
34 8
		$path = 'languages' . DIRECTORY_SEPARATOR . $this->_filePlaceholder . '.json';
35
		$setupArray =
36
		[
37 8
			'query' => $specialFilter->sanitize($this->_request->getQuery('l')),
38 8
			'session' => $this->_request->getSession('language'),
39 8
			'contents' => $contentModel->getByTableAndId($lastTable, $lastId)->language,
0 ignored issues
show
It seems like $lastTable defined by $this->_registry->get('lastTable') on line 32 can also be of type array; however, Redaxscript\Model\Content::getByTableAndId() 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...
It seems like $lastId defined by $this->_registry->get('lastId') on line 33 can also be of type array or string; however, Redaxscript\Model\Content::getByTableAndId() does only seem to accept null|integer, 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...
40 8
			'settings' => $dbStatus === 2 ? $settingModel->get('language') : null,
41 8
			'browser' => substr($this->_request->getServer('HTTP_ACCEPT_LANGUAGE'), 0, 2),
42 8
			'fallback' => 'en'
43
		];
44
45
		/* detect language */
46
47 8
		$this->_output = $this->_detect('language', $path, $setupArray);
48 8
	}
49
}
50