Completed
Push — master ( 14c945...6811c1 )
by Henry
05:37
created

Template   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A autorun() 0 21 2
1
<?php
2
namespace Redaxscript\Detector;
3
4
use Redaxscript\Model;
5
6
/**
7
 * children class to detect the current template
8
 *
9
 * @since 2.0.0
10
 *
11
 * @package Redaxscript
12
 * @category Detector
13
 * @author Henry Ruhs
14
 */
15
16
class Template extends DetectorAbstract
17
{
18
	/**
19
	 * automate run
20
	 *
21
	 * @since 2.1.0
22
	 */
23
24
	public function autorun() : void
25
	{
26
		$settingModel = new Model\Setting();
27
		$contentModel = new Model\Content();
28
		$dbStatus = $this->_registry->get('dbStatus');
29
		$lastTable = $this->_registry->get('lastTable');
30
		$lastId = $this->_registry->get('lastId');
31
		$path = 'templates' . DIRECTORY_SEPARATOR . $this->_filePlaceholder . DIRECTORY_SEPARATOR . 'index.phtml';
32
		$setupArray =
33
		[
34
			'query' => $this->_request->getQuery('t'),
35
			'session' => $this->_request->getSession('template'),
36
			'contents' => $contentModel->getByTableAndId($lastTable, $lastId)->template,
0 ignored issues
show
Bug introduced by redaxmedia
It seems like $lastTable defined by $this->_registry->get('lastTable') on line 29 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 30 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...
37
			'settings' => $dbStatus === 2 ? $settingModel->get('template') : null,
38
			'fallback' => 'default'
39
		];
40
41
		/* detect template */
42
43
		$this->_output = $this->_detect('template', $path, $setupArray);
44
	}
45
}
46