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

Template   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 6
dl 0
loc 32
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A autorun() 0 23 2
1
<?php
2
namespace Redaxscript\Detector;
3
4
use Redaxscript\Filter;
5
use Redaxscript\Model;
6
7
/**
8
 * children class to detect the current template
9
 *
10
 * @since 2.0.0
11
 *
12
 * @package Redaxscript
13
 * @category Detector
14
 * @author Henry Ruhs
15
 */
16
17
class Template extends DetectorAbstract
18
{
19
	/**
20
	 * automate run
21
	 *
22
	 * @since 2.1.0
23
	 */
24
25 7
	public function autorun() : void
26
	{
27 7
		$settingModel = new Model\Setting();
28 7
		$contentModel = new Model\Content();
29 7
		$specialFilter = new Filter\Special();
30 7
		$dbStatus = $this->_registry->get('dbStatus');
31 7
		$lastTable = $this->_registry->get('lastTable');
32 7
		$lastId = $this->_registry->get('lastId');
33 7
		$content = $contentModel->getByTableAndId($lastTable, $lastId);
0 ignored issues
show
Bug introduced by
It seems like $lastTable defined by $this->_registry->get('lastTable') on line 31 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
It seems like $lastId defined by $this->_registry->get('lastId') on line 32 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...
34 7
		$path = 'templates' . DIRECTORY_SEPARATOR . $this->_filePlaceholder . DIRECTORY_SEPARATOR . 'index.phtml';
35
		$setupArray =
36
		[
37 7
			'query' => $specialFilter->sanitize($this->_request->getQuery('t')),
0 ignored issues
show
Bug introduced by
It seems like $this->_request->getQuery('t') targeting Redaxscript\Request::getQuery() can also be of type array; however, Redaxscript\Filter\Special::sanitize() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
38 7
			'session' => $this->_request->getSession('template'),
39 7
			'contents' => $content->template ?? null,
40 7
			'settings' => $dbStatus === 2 ? $settingModel->get('template') : null,
41 7
			'fallback' => 'default'
42
		];
43
44
		/* detect template */
45
46 7
		$this->_output = $this->_detect('template', $path, $setupArray);
47 7
	}
48
}
49