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

MappingA::setTemplatePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * @package application
4
 * @subpackage sitemaps
5
 * @author marius orcisk <[email protected]>
6
 * @date 09.11.29
7
 */
8
namespace vsc\application\sitemaps;
9
10
use vsc\application\controllers\ExceptionController;
11
use vsc\infrastructure\urls\Url;
12
use vsc\infrastructure\urls\UrlParserA;
13
use vsc\infrastructure\Base;
14
use vsc\infrastructure\Object;
15
use vsc\presentation\requests\HttpAuthenticationA;
16
17
abstract class MappingA extends Object {
18
	/**
19
	 * @var  string
20
	 */
21
	private $sRegex;
22
	/**
23
	 * @var string
24
	 */
25
	private $sPath;
26
	/**
27
	 * @var string
28
	 */
29
	private $sTemplate;
30
	/**
31
	 * the local template path - will be used to compose something like
32
	 * this->sViewPath . view->typeOfView . this->sTemplate
33
	 *
34
	 * @var string
35
	 */
36
	private $sViewPath;
37
38
	private $bIsStatic = false;
39
40
	private $aControllerMaps = array();
41
42
	private $aTaintedVars = [];
43
44
	private $sMatchingUrl;
45
46
	/**
47
	 * @var int
48
	 */
49
	private $iAuthenticationType = null;
50
51
	/**
52
	 * @param MappingA $oMap
53
	 */
54
	abstract protected function mergeResources($oMap);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
55
	/**
56
	 * @return string
57
	 */
58
	abstract public function getTitle();
59
	/**
60
	 * @param string $sTitle
61
	 */
62
	abstract public function setTitle($sTitle);
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
63
	/**
64
	 * @param string $sPath
65
	 * @param string $sRegex
66
	 */
67 24
	public function __construct($sPath, $sRegex) {
68 24
		$this->sPath = $sPath;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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...
69 24
		$this->sRegex = $sRegex;
70 24
	}
71
72 20
	public function getRegex() {
73 20
		return $this->sRegex;
74
	}
75
76
	/**
77
	 * @param bool $bStatic
78
	 */
79 2
	public function setIsStatic($bStatic) {
80 2
		$this->bIsStatic = $bStatic;
81 2
	}
82
83
	/**
84
	 * @return bool
85
	 */
86 2
	public function isStatic() {
87 2
		return $this->bIsStatic;
88
	}
89
90
	/**
91
	 * @param MappingA $oMap
92
	 */
93 21
	protected function mergePaths($oMap) {
94 21
		$sParentPath = $oMap->getTemplatePath();
95 21
		if (!is_null($sParentPath) && is_null($this->getTemplatePath())) {
96 1
			$this->setTemplatePath($sParentPath);
97
		}
98
99 21
		$sParentTemplate = $oMap->getTemplate();
100 21
		if (!is_null($sParentTemplate) && is_null($this->getTemplate())) {
101
			$this->setTemplate($sParentTemplate);
102
		}
103
104 21
		if (($this instanceof ContentTypeMappingInterface) && ($oMap instanceof ContentTypeMappingInterface)) {
105
			/** @var ContentTypeMappingInterface $oMap */
106 20
			$sParentMainTemplatePath = $oMap->getMainTemplatePath();
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $sParentMainTemplatePath exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
107 20
			if (is_null($this->getMainTemplatePath())) {
0 ignored issues
show
Documentation Bug introduced by
The method getMainTemplatePath does not exist on object<vsc\application\sitemaps\MappingA>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
108 1
				$this->setMainTemplatePath($sParentMainTemplatePath);
0 ignored issues
show
Documentation Bug introduced by
The method setMainTemplatePath does not exist on object<vsc\application\sitemaps\MappingA>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
109
			}
110 20
			$sParentMainTemplate = $oMap->getMainTemplate();
111 20
			if (is_null($this->getMainTemplate())) {
0 ignored issues
show
Documentation Bug introduced by
The method getMainTemplate does not exist on object<vsc\application\sitemaps\MappingA>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
112 1
				$this->setMainTemplate($sParentMainTemplate);
0 ignored issues
show
Documentation Bug introduced by
The method setMainTemplate does not exist on object<vsc\application\sitemaps\MappingA>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
113
			}
114
		}
115 21
	}
116
117
	/**
118
	 * @param MappingA $oMap
0 ignored issues
show
Documentation introduced by
Should the type for parameter $oMap not be MappingA|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
119
	 * @return $this
120
	 */
121 20
	public function merge($oMap = null) {
122 20
		if (MappingA::isValid($oMap)) {
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
123 20
			$this->mergeResources($oMap);
0 ignored issues
show
Bug introduced by
It seems like $oMap defined by parameter $oMap on line 121 can be null; however, vsc\application\sitemaps...pingA::mergeResources() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
124 20
			$this->mergePaths($oMap);
0 ignored issues
show
Bug introduced by
It seems like $oMap defined by parameter $oMap on line 121 can be null; however, vsc\application\sitemaps\MappingA::mergePaths() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
125
126 20
			$sTitle = $this->getTitle();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
127 20
			$sMapTitle = $oMap->getTitle();
0 ignored issues
show
Bug introduced by
It seems like $oMap is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
128 20
			if (empty($sTitle) && !empty($sMapTitle)) {
129
				$this->setTitle($sMapTitle);
130
			}
131 20
			$this->iAuthenticationType |= $oMap->getAuthenticationType();
132
		}
133 20
		return $this;
134
	}
135
136
	/**
137
	 * @param string $sPath
138
	 * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
139
	 * @throws ExceptionSitemap
140
	 */
141 21
	public function setTemplatePath($sPath) {
142 21
		$this->sViewPath = $this->getValidPath($sPath);
143 21
	}
144
145
	/**
146
	 * @return string
147
	 */
148 21
	public function getTemplatePath() {
149 21
		return $this->sViewPath;
150
	}
151
152
	/**
153
	 * @param string $sPath
154
	 */
155 18
	public function setTemplate($sPath) {
156 18
		$this->sTemplate = $sPath;
157 18
	}
158
159
	/**
160
	 * @return string
161
	 */
162 19
	public function getTemplate() {
163 19
		return $this->sTemplate;
164
	}
165
166
	/**
167
	 * @return string
168
	 */
169 24
	public function getPath() {
170 24
		return $this->sPath;
171
	}
172
173
	/**
174
	 * @deprecated
175
	 * @param string $sRegex
176
	 * @param string $sPath
0 ignored issues
show
Documentation introduced by
Should the type for parameter $sPath not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
177
	 * @throws ExceptionController
178
	 * @throws ExceptionSitemap
179
	 * @returns ClassMap
180
	 */
181
	public function mapController($sRegex, $sPath = null) {
182
		return $this->map($sRegex, $sPath);
183
	}
184
185
	/**
186
	 *
187
	 * @param string $sRegex
188
	 * @param string $sPath
0 ignored issues
show
Documentation introduced by
Should the type for parameter $sPath not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
189
	 * @throws ExceptionController
190
	 * @throws ExceptionSitemap
191
	 * @returns ClassMap
192
	 */
193 22
	public function map($sRegex, $sPath = null) {
194 22
		if (empty($sRegex)) {
195
			throw new ExceptionSitemap('An URI must be present.');
196
		}
197 22
		if (is_null($sPath)) {
198
			// if we only have one parameter, we treat it as a path
199 1
			$sPath = $sRegex;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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...
200 1
			$sRegex = $this->getRegex();
201
		}
202
203 22
		$sKey = $sRegex;
204 22
		if (array_key_exists($sKey, $this->aControllerMaps)) {
205
			unset($this->aControllerMaps[$sKey]);
206
		}
207 22
		if (ClassMap::isValidMap($sPath)) {
208
			// instead of a path we have a namespace
209 21
			$oNewMap = new ClassMap($sPath, $sKey);
210 21
			$oNewMap->setModuleMap($this);
211 21
			$oNewMap->merge($this);
212
213 21
			$this->aControllerMaps[$sKey] = $oNewMap;
214
215 21
			return $oNewMap;
216
		}
217 1
	}
218
219
	/**
220
	 * @return MappingA[]
221
	 */
222 20
	public function getControllerMaps() {
223 20
		return $this->aControllerMaps;
224
	}
225
226
	/**
227
	 * @param string[] $aVars
228
	 */
229 18
	public function setTaintedVars($aVars) {
230 18
		$this->aTaintedVars = $aVars;
231 18
	}
232
233 10
	public function getTaintedVars() {
234 10
		return $this->aTaintedVars;
235
	}
236
237
	/**
238
	 * @param string $sUrl
239
	 */
240 19
	public function setUrl($sUrl) {
241 19
		$this->sMatchingUrl = $sUrl;
242 19
	}
243
244
	/**
245
	 * @returns Url
246
	 */
247 2
	public function getUrl() {
248 2
		$sRegex = '#(' . str_replace('#', '\#', $this->getRegex()) . ')#iUu';
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...
249 2
		$bHaveMatch = preg_match($sRegex, $this->sMatchingUrl, $aMatches);
250
251 2
		if ($bHaveMatch) {
252 2
			$url = new Url();
253 2
			$url->setPath($aMatches[0]);
254 2
			return $url;
255
		} else {
256
			return new Base();
257
		}
258
	}
259
260 2
	public function setAuthenticationType($iAuthenticationType) {
261 2
		$this->iAuthenticationType = $iAuthenticationType;
262 2
	}
263
264 22
	public function getAuthenticationType() {
265 22
		return $this->iAuthenticationType;
266
	}
267
268
	/**
269
	 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
270
	 */
271 1
	public function getValidAuthenticationSchemas() {
272 1
		return HttpAuthenticationA::getAuthenticationSchemas($this->iAuthenticationType);
273
	}
274
275
	/**
276
	 * @return bool
277
	 */
278 2
	public function requiresAuthentication() {
279 2
		return ($this->iAuthenticationType != HttpAuthenticationA::NONE);
280
	}
281
282
	/**
283
	 * @param Object $mappedObject
284
	 * @return boolean
285
	 */
286 1
	public function maps(Object $mappedObject)
287
	{
288 1
		return (bool)stristr(get_class($mappedObject), substr(basename($this->getPath()), 0, -4));
289
	}
290
291
	/**
292
	 * @param string $sPath
293
	 * @return string
294
	 * @throws ExceptionSitemap
295
	 */
296 21
	protected function getValidPath($sPath) {
297 21
		if (!is_dir($sPath)) {
298 2
			if (!ModuleMap::isValid($this) && !ModuleMap::isValid($this->getModuleMap())) {
0 ignored issues
show
Documentation Bug introduced by
The method getModuleMap does not exist on object<vsc\application\sitemaps\MappingA>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
299
				throw new ExceptionSitemap('No reference module path to use for relative paths');
300
			}
301 2
			$sPath = $this->getModulePath() . $sPath;
0 ignored issues
show
Documentation Bug introduced by
The method getModulePath does not exist on object<vsc\application\sitemaps\MappingA>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
302
		}
303 21
		$sPath = realpath($sPath);
304 21
		if (!is_dir($sPath)) {
305
			throw new ExceptionSitemap('Template path is not valid.');
306
		}
307
308 21
		return $sPath . DIRECTORY_SEPARATOR;
309
	}
310
}
311
312