Language   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 31
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A autorun() 0 22 2
1
<?php
2
namespace Redaxscript\Detector;
3
4
use Redaxscript\Model;
5
use function substr;
6
7
/**
8
 * children class to detect the current 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
	public function autorun() : void
26
	{
27 8
		$settingModel = new Model\Setting();
28 8
		$contentModel = new Model\Content();
29 8
		$dbStatus = $this->_registry->get('dbStatus');
30 8
		$lastTable = $this->_registry->get('lastTable');
31 8
		$lastId = $this->_registry->get('lastId');
32 8
		$path = 'languages' . DIRECTORY_SEPARATOR . $this->_filePlaceholder . '.json';
33
		$setupArray =
34
		[
35 8
			'query' => $this->_request->getQuery('l'),
36 8
			'session' => $this->_request->getSession('language'),
37 8
			'contents' => $contentModel->getByTableAndId($lastTable, $lastId)->language,
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $lastTable defined by $this->_registry->get('lastTable') on line 30 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...
Bug introduced by redaxmedia
It seems like $lastId defined by $this->_registry->get('lastId') on line 31 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...
38 8
			'settings' => $dbStatus === 2 ? $settingModel->get('language') : null,
39 8
			'browser' => substr($this->_request->getServer('HTTP_ACCEPT_LANGUAGE'), 0, 2),
40 8
			'fallback' => 'en'
41
		];
42
43
		/* detect language */
44
45 8
		$this->_output = $this->_detect('language', $path, $setupArray);
46 8
	}
47
}
48