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.

MappingA::mapController()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
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\BaseObject;
15
use vsc\presentation\requests\HttpAuthenticationA;
16
17
abstract class MappingA extends BaseObject {
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;
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();
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 21
	public function merge($oMap = null) {
122 21
		if (MappingA::isValid($oMap)) {
123 21
			$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 21
			$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
			// maybe I should merge the regexes too like processor_regex . '.*' . controller_regex
126
127 21
			$sTitle = $this->getTitle();
128 21
			$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...
129 21
			if (empty($sTitle) && !empty($sMapTitle)) {
130
				$this->setTitle($sMapTitle);
131
			}
132 21
			$this->iAuthenticationType |= $oMap->getAuthenticationType();
133
		}
134 21
		return $this;
135
	}
136
137
	/**
138
	 * @param string $sPath
139
	 * @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...
140
	 * @throws ExceptionSitemap
141
	 */
142 21
	public function setTemplatePath($sPath) {
143 21
		$this->sViewPath = $this->getValidPath($sPath);
144 21
	}
145
146
	/**
147
	 * @return string
148
	 */
149 21
	public function getTemplatePath() {
150 21
		return $this->sViewPath;
151
	}
152
153
	/**
154
	 * @param string $sPath
155
	 */
156 18
	public function setTemplate($sPath) {
157 18
		$this->sTemplate = $sPath;
158 18
	}
159
160
	/**
161
	 * @return string
162
	 */
163 19
	public function getTemplate() {
164 19
		return $this->sTemplate;
165
	}
166
167
	/**
168
	 * @return string
169
	 */
170 24
	public function getPath() {
171 24
		return $this->sPath;
172
	}
173
174
	/**
175
	 * @deprecated
176
	 * @param string $sRegex
177
	 * @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...
178
	 * @throws ExceptionController
179
	 * @throws ExceptionSitemap
180
	 * @returns ClassMap
181
	 */
182
	public function mapController($sRegex, $sPath = null) {
183
		return $this->map($sRegex, $sPath);
184
	}
185
186
	/**
187
	 *
188
	 * @param string $sRegex
189
	 * @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...
190
	 * @throws ExceptionController
191
	 * @throws ExceptionSitemap
192
	 * @returns ClassMap
193
	 */
194 22
	public function map($sRegex, $sPath = null) {
195 22
		if (empty($sRegex)) {
196
			throw new ExceptionSitemap('An URI must be present.');
197
		}
198 22
		if (is_null($sPath)) {
199
			// if we only have one parameter, we treat it as a path
200 1
			$sPath = $sRegex;
201 1
			$sRegex = $this->getRegex();
202
		}
203
204 22
		$sKey = $sRegex;
205 22
		if (array_key_exists($sKey, $this->aControllerMaps)) {
206
			unset($this->aControllerMaps[$sKey]);
207
		}
208 22
		if (ClassMap::isValidMap($sPath)) {
209
			// instead of a path we have a namespace
210 21
			$oNewMap = new ClassMap($sPath, $sKey);
211 21
			$oNewMap->setModuleMap($this);
212 21
			$oNewMap->merge($this);
213
214 21
			$this->aControllerMaps[$sKey] = $oNewMap;
215
216 21
			return $oNewMap;
217
		}
218 1
	}
219
220
	/**
221
	 * @return MappingA[]
222
	 */
223 20
	public function getControllerMaps() {
224 20
		return $this->aControllerMaps;
225
	}
226
227
	/**
228
	 * @param string[] $aVars
229
	 */
230 18
	public function setTaintedVars($aVars) {
231 18
		$this->aTaintedVars = $aVars;
232 18
	}
233
234 10
	public function getTaintedVars() {
235 10
		return $this->aTaintedVars;
236
	}
237
238
	/**
239
	 * @param string $sUrl
240
	 */
241 19
	public function setUrl($sUrl) {
242 19
		$this->sMatchingUrl = $sUrl;
243 19
	}
244
245
	/**
246
	 * @returns Url
247
	 */
248 2
	public function getUrl() {
249 2
		$sRegex = '#(' . str_replace('#', '\#', $this->getRegex()) . ')#iUu';
250 2
		$bHaveMatch = preg_match($sRegex, $this->sMatchingUrl, $aMatches);
251
252 2
		if ($bHaveMatch) {
253 2
			$url = new Url();
254 2
			$url->setPath($aMatches[0]);
255 2
			return $url;
256
		} else {
257
			return new Base();
258
		}
259
	}
260
261 2
	public function setAuthenticationType($iAuthenticationType) {
262 2
		$this->iAuthenticationType = $iAuthenticationType;
263 2
	}
264
265 22
	public function getAuthenticationType() {
266 22
		return $this->iAuthenticationType;
267
	}
268
269
	/**
270
	 * @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...
271
	 */
272 1
	public function getValidAuthenticationSchemas() {
273 1
		return HttpAuthenticationA::getAuthenticationSchemas($this->iAuthenticationType);
274
	}
275
276
	/**
277
	 * @return bool
278
	 */
279 2
	public function requiresAuthentication() {
280 2
		return ($this->iAuthenticationType != HttpAuthenticationA::NONE);
281
	}
282
283
	/**
284
	 * @param Object $mappedObject
285
	 * @return boolean
286
	 */
287 1
	public function maps(BaseObject $mappedObject)
288
	{
289 1
		return (bool)stristr(get_class($mappedObject), substr(basename($this->getPath()), 0, -4));
290
	}
291
292
	/**
293
	 * @param string $sPath
294
	 * @return string
295
	 * @throws ExceptionSitemap
296
	 */
297 21
	protected function getValidPath($sPath) {
298 21
		if (!is_dir($sPath)) {
299 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...
300
				throw new ExceptionSitemap('No reference module path to use for relative paths');
301
			}
302 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...
303
		}
304 21
		$sPath = realpath($sPath);
305 21
		if (!is_dir($sPath)) {
306
			throw new ExceptionSitemap('Template path is not valid.');
307
		}
308
309 21
		return $sPath . DIRECTORY_SEPARATOR;
310
	}
311
}
312
313