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.

ProcessorA::delegateRequest()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0052

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 3
dl 0
loc 22
ccs 11
cts 12
cp 0.9167
crap 3.0052
rs 9.568
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package application
4
 * @subpackage processors
5
 * @author marius orcsik <[email protected]>
6
 * @date 09.08.31
7
 */
8
namespace vsc\application\processors;
9
10
use vsc\application\sitemaps\ClassMap;
11
use vsc\application\sitemaps\MappingA;
12
use vsc\domain\models\ModelA;
13
use vsc\infrastructure\vsc;
14
use vsc\infrastructure\BaseObject;
15
use vsc\presentation\requests\HttpRequestA;
16
use vsc\presentation\responses\HttpResponse;
17
use vsc\presentation\responses\HttpResponseA;
18
use vsc\application\dispatchers\RwDispatcher;
19
20
abstract class ProcessorA extends BaseObject implements ProcessorInterface {
21
	private $oCurrentMap;
22
	protected $aLocalVars = array();
23
24
	/**
25
	 * @returns ClassMap
26
	 */
27 3
	public function getMap() {
28 3
		if (MappingA::isValid($this->oCurrentMap)) {
29 2
			return $this->oCurrentMap;
30
		} else {
31 1
			$oMirror = new \ReflectionClass($this);
32 1
			return new ClassMap($oMirror->getName(), '.*');
0 ignored issues
show
Bug introduced by
Consider using $oMirror->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
33
		}
34
	}
35
36
	/**
37
	 * @param MappingA $oMap
38
	 */
39 10
	public function setMap(MappingA $oMap) {
40 10
		$this->oCurrentMap = $oMap;
41 10
		$aTainted = $oMap->getTaintedVars();
42 10
		if (is_array($aTainted) && count($aTainted) >= 1) {
43
			$this->setLocalVars($aTainted);
44
		}
45 10
	}
46
47
	/**
48
	 *
49
	 * @param array $aVars
50
	 * @param bool $bPreserveKeys
51
	 * @return void
52
	 */
53 1
	public function setLocalVars($aVars = array(), $bPreserveKeys = false) {
54 1
		if ($bPreserveKeys) {
55 1
			$this->aLocalVars = array_merge($this->aLocalVars, $aVars);
56
		} else {
57
			// This needs improvement to take into account incoming arrays
58
			//  containing both string keys - which exist or not in the $aLocalVars array
59
			//  and numeric indexes
60
			foreach ($this->aLocalVars as $sKey => $sValue) {
61
				$this->aLocalVars[$sKey] = array_shift($aVars);
62
			}
63
		}
64 1
	}
65
66
	/**
67
	 * @return array
68
	 */
69 1
	public function getLocalVars() {
70 1
		return $this->aLocalVars;
71
	}
72
73
	/**
74
	 * @param string $sVar
75
	 * @param string $sValue
76
	 * @return bool
77
	 */
78 2
	public function setVar($sVar, $sValue) {
79 2
		if (array_key_exists($sVar, $this->aLocalVars)) {
80 1
			$this->aLocalVars[$sVar] = $sValue;
81 1
			return true;
82
		}
83 1
		return false;
84
	}
85
86
	/**
87
	 * @param string $sVar
88
	 * @return null
89
	 */
90 1
	public function getVar($sVar) {
91 1
		if (array_key_exists($sVar, $this->aLocalVars)) {
92 1
			return $this->aLocalVars[$sVar];
93
		} else {
94
			return null;
95
		}
96
	}
97
98
	/**
99
	 *
100
	 * @see ProcessorI::delegateRequest()
101
	 * @param HttpRequestA $oHttpRequest
102
	 * @param ProcessorA $oNewProcessor
103
	 * @param HttpResponseA $oResponse
0 ignored issues
show
Documentation introduced by
Should the type for parameter $oResponse not be null|HttpResponseA?

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...
104
	 * @returns ModelA
105
	 */
106 1
	public function delegateRequest(HttpRequestA $oHttpRequest, ProcessorA $oNewProcessor, HttpResponseA $oResponse = null) {
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...
107 1
		$oDispatcher = vsc::getEnv()->getDispatcher();
108
		/** @var ClassMap $oMap */
109 1
		$oMap = $oDispatcher->getSiteMap()->findProcessorMap($oNewProcessor);
110
111 1
		if (MappingA::isValid($oMap)) {
112 1
			$oNewProcessor->setMap($oMap);
113 1
			$oNewProcessor->init();
114
115
			/* @var RwDispatcher $oDispatcher */
116 1
			$oMap->merge($this->getMap());
117
118 1
			if (HttpResponse::isValid($oResponse)) {
119
				$oMap->setResponse($oResponse);
0 ignored issues
show
Bug introduced by
It seems like $oResponse defined by parameter $oResponse on line 106 can be null; however, vsc\application\sitemaps...MapTrait::setResponse() 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...
120
			}
121
122 1
			$this->setMap($oMap);
123
		}
124 1
		$oNewProcessor->setLocalVars($this->getLocalVars(), true);
125
126 1
		return $oNewProcessor->handleRequest($oHttpRequest);
127
	}
128
}
129