GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 7b42e1...c93f43 )
by Marius
10:41 queued 04:09
created

ControllerMapTrait::setMainTemplatePath()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 4
nop 1
dl 0
loc 12
ccs 7
cts 8
cp 0.875
crap 3.0175
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace vsc\application\sitemaps;
3
4
use vsc\ExceptionPath;
5
use vsc\presentation\views\ViewA;
6
7
trait ControllerMapTrait {
8
	private $sMainTemplatePath;
9
	private $sMainTemplate;
10
11
	private $sViewPath;
12
	private $oView;
13
14
	/**
15
	 * @return ModuleMap
16
	 */
17
	abstract public function getModuleMap();
18
19
	/**
20
	 * @param string $sPath
21
	 * @return bool
22
	 * @throws \vsc\ExceptionPath
23
	 */
24 3
	public function setMainTemplatePath($sPath) {
25 3
		$sMainTemplatePath = realpath($sPath);
26 3
		if (!is_dir($sMainTemplatePath)) {
27 2
			$sMainTemplatePath = realpath($this->getModuleMap()->getModulePath() . DIRECTORY_SEPARATOR . $sPath);
28
		}
29 3
		if (!is_dir($sMainTemplatePath)) {
30
			throw new ExceptionPath(sprintf('Path [%s] does not exist', $sPath));
31
		}
32 3
		$this->sMainTemplatePath = $sMainTemplatePath;
33
34 3
		return true;
35
	}
36
37
	/**
38
	 * @return string
39
	 */
40 21
	public function getMainTemplatePath() {
41
		// if we didn't provide the controller with a main template path we check the module
42 21
		if (is_null($this->sMainTemplatePath)) {
43 19
			if ($this->getModuleMap() instanceof ContentTypeMappingInterface) {
44 19
				$this->sMainTemplatePath = $this->getModuleMap()->getMainTemplatePath();
45
			}
46
		}
47
48 21
		if (is_null($this->sMainTemplatePath)) {
49
			// back-up
50 19
			$this->sMainTemplatePath = VSC_RES_PATH . 'templates';
51
		}
52 21
		if (substr($this->sMainTemplatePath, -1) != DIRECTORY_SEPARATOR) {
53 21
			$this->sMainTemplatePath .= DIRECTORY_SEPARATOR;
54
		}
55 21
		return $this->sMainTemplatePath;
56
	}
57
58
	/**
59
	 * @param string $sPath
60
	 */
61 1
	public function setMainTemplate($sPath) {
62 1
		$this->sMainTemplate = $sPath;
63 1
	}
64
65
	/**
66
	 * @return string
67
	 */
68 21
	public function getMainTemplate() {
69
		// if we didn't provide the controller with a main template path we check the module
70 21
		if (is_null($this->sMainTemplate)) {
71 20
			if ($this->getModuleMap() instanceof ContentTypeMappingInterface) {
72 20
				$this->sMainTemplate = $this->getModuleMap()->getMainTemplate();
73
			}
74
		}
75 21
		if (is_null($this->sMainTemplate)) {
76
			// back-up
77 20
			$this->sMainTemplate = 'main.php';
78
		}
79 21
		return $this->sMainTemplate;
80
	}
81
82
	/**
83
	 *
84
	 * To allow a single controller type to return a different type of view
85
	 * @param string|object $mView
86
	 * @throws ExceptionPath
87
	 */
88 3
	public function setView($mView) {
89 3
		if (ViewA::isValid($mView)) {
90
			$this->oView = $mView;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
91
			$this->sViewPath = get_class($mView);
92 3
		} elseif (ClassMap::isValidMap($mView)) {
0 ignored issues
show
Bug introduced by
It seems like $mView defined by parameter $mView on line 88 can also be of type object; however, vsc\application\sitemaps\ClassMap::isValidMap() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
93 3
			$this->sViewPath = $mView;
94
		} else {
95
			throw new ExceptionPath('View path [' . $mView . '] is not valid.');
96
		}
97 3
	}
98
99 3
	public function getViewPath() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
100 3
		return $this->sViewPath;
101
	}
102
103 6
	public function getView() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
104 6
		if (!ViewA::isValid($this->oView) && !is_null($this->sViewPath)) {
105 3
			if (stristr(basename($this->sViewPath), '.') === false && !is_file($this->sViewPath)) {
106 3
				$sClassName = $this->sViewPath;
107
			} elseif (is_file($this->sViewPath)) {
108
				$sViewPath = $this->getViewPath();
109
				try {
110
					include ($sViewPath);
111
				} catch (\Exception $e) {
112
					\vsc\_e($e);
113
				}
114
				$sClassName = SiteMapA::getClassName($sViewPath);
115
			}
116
		}
117 6
		if (!empty($sClassName)) {
118 3
			$this->oView = new $sClassName();
119
		}
120 6
		return $this->oView;
121
	}
122
}
123