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.

vsc::getHttpRequest()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 6

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 0
dl 0
loc 11
ccs 3
cts 6
cp 0.5
crap 6
rs 9.9
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package infrastructure
4
 * @author marius orcsik <[email protected]>
5
 * @date 09.08.31
6
 */
7
namespace vsc\infrastructure;
8
9
use vsc\application\dispatchers\DispatcherA;
10
use vsc\application\dispatchers\HttpDispatcherA;
11
use vsc\application\dispatchers\RwDispatcher;
12
use vsc\application\sitemaps\ModuleMap;
13
use vsc\application\sitemaps\SiteMapA;
14
use vsc\presentation\requests\HttpRequestA;
15
use vsc\presentation\requests\RawHttpRequest;
16
use vsc\presentation\requests\RwHttpRequest;
17
use vsc\presentation\responses\HttpResponse;
18
use vsc\presentation\responses\HttpResponseA;
19
20
class vsc extends BaseObject {
21
	/**
22
	 * @var vsc
23
	 */
24
	static private $oInstance;
25
26
	/**
27
	 * @var HttpRequestA
28
	 */
29
	private $oRequest = null;
30
31
	/**
32
	 * @var HttpResponseA
33
	 */
34
	private $oResponse = null;
35
36
	/**
37
	 * @var DispatcherA
38
	 */
39
	private $oDispatcher;
40
41
	/**
42
	 * @param vsc $envObject
43
	 */
44 19
	public static function setInstance(vsc $envObject) {
45 19
		self::$oInstance = $envObject;
46 19
	}
47
48
	/**
49
	 * @return vsc
50
	 */
51 26
	public static function getEnv() {
52 26
		if (!(vsc::isValid(self::$oInstance))) {
53
			self::$oInstance = new self();
54
		}
55 26
		return self::$oInstance;
56
	}
57
58
	/**
59
	 * @param HttpRequestA $oRequest
60
	 */
61 18
	public function setHttpRequest(HttpRequestA $oRequest) {
62 18
		if (HttpRequestA::isValid($oRequest)) {
63 18
			$this->oRequest = $oRequest;
64
		}
65 18
	}
66
67
	/**
68
	 * @returns HttpRequestA
69
	 */
70 20
	public function getHttpRequest() {
71 20
		if (is_null($this->oRequest)) {
72
			// @todo FIX this ugly stuff
73
			if (array_key_exists('CONTENT_TYPE', $_SERVER) && strlen($_SERVER['CONTENT_TYPE']) > 0) {
74
				$this->oRequest = new RawHttpRequest();
75
			} else {
76
				$this->oRequest = new RwHttpRequest();
77
			}
78
		}
79 20
		return $this->oRequest;
80
	}
81
82
	/**
83
	 * @param HttpResponseA $oResponse
84
	 */
85 1
	public function setHttpResponse(HttpResponseA $oResponse) {
86 1
		if (HttpResponseA::isValid($oResponse) && (is_null($this->oResponse) || get_class($this->oResponse) != get_class($oResponse))) {
87 1
			$this->oResponse = $oResponse;
88
		}
89 1
	}
90
91
	/**
92
	 * @returns HttpResponseA
93
	 */
94 1
	public function getHttpResponse() {
95 1
		if (is_null($this->oResponse)) {
96 1
			$this->oResponse = new HttpResponse();
97
		}
98 1
		return $this->oResponse;
99
	}
100
101
	/**
102
	 * @param HttpDispatcherA $oDispatcher
103
	 */
104 1
	public function setDispatcher($oDispatcher) {
105 1
		if (DispatcherA::isValid($oDispatcher)) {
106 1
			$this->oDispatcher = $oDispatcher;
107
		}
108 1
	}
109
110
	/**
111
	 * @returns HttpDispatcherA
112
	 */
113 3
	public function getDispatcher() {
114 3
		if (!HttpDispatcherA::isValid($this->oDispatcher)) {
115 1
			$this->oDispatcher = new RwDispatcher();
116
		}
117 3
		return $this->oDispatcher;
118
	}
119
120
	/**
121
	 * @return SiteMapA
122
	 */
123 2
	public function getSiteMap() {
124 2
		return $this->getDispatcher()->getSiteMap();
125
	}
126
127
	/**
128
	 * @return boolean
129
	 */
130 1
	public function isDevelopment() {
131
		return (
132 1
			self::isCli() || (
133
				stristr($_SERVER['REMOTE_ADDR'], '127.0.0.1') != false ||
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stristr($_SERVER['REMOTE_ADDR'], '127.0.0.1') of type string to the boolean false. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
134 1
				stristr($_SERVER['REMOTE_ADDR'], '192.168') != false
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stristr($_SERVER['REMOTE_ADDR'], '192.168') of type string to the boolean false. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
135
			)
136
		);
137
	}
138
139
	/**
140
	 * @return bool
141
	 */
142 4
	protected function _isCli() {
143 4
		return (php_sapi_name() == 'cli');
144
	}
145
146
	/**
147
	 * @return bool
148
	 */
149 5
	public static function isCli() {
150 5
		return self::getEnv()->_isCli();
151
	}
152
153
	/**
154
	 * @return string
155
	 */
156 1
	public static function name() {
157 1
		return 'V<sup>S<sup>C</sup></sup>';
158
	}
159
160
	/**
161
	 * returns an end of line, based on the environment
162
	 * @return string
163
	 */
164 1
	public static function nl() {
165 1
		return self::isCli() ? "\n" : '<br/>' . "\n";
166
	}
167
168
	/**
169
	 * @param array ...$values
170
	 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be null|string?

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...
171
	 */
172 1
	public static function d(...$values) {
173 1
		$output = '';
174 1
		for ($i = 0; $i < ob_get_level(); $i++) {
175
			// cleaning the buffers
176 1
			ob_end_clean();
177
		}
178
179 1
		if (!self::isCLi() && self::getEnv()->getHttpRequest()->accepts('application/json')) {
180
			$output = json_encode($values);
181 1
		} elseif (self::isCLi() || self::getEnv()->getHttpRequest()->accepts('text/html')) {
182 1
			foreach ($values as $object) {
183 1
				ob_start();
184 1
				var_dump($object);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($object); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
185 1
				$output .= ob_get_clean();
186
187 1
				if (!self::isCli()) {
188 1
					$output .= '<hr/>' . "\n";
189
				}
190
			}
191
		}
192
193 1
		if (!stristr($_SERVER['PHP_SELF'], 'phpunit')) {
194
			ob_start();
195
			debug_print_backtrace();
196
			$output .= ob_get_clean();
197
198
			if (self::isCLi() || self::getEnv()->getHttpRequest()->accepts('application/json')) {
199
				echo StringUtils::stripTags(StringUtils::br2nl($output));
200
			} elseif (self::getEnv()->getHttpRequest()->accepts('text/html')) {
201
				echo '<pre>' . $output . '</pre>';
202
			} else {
203
				echo StringUtils::stripTags(StringUtils::br2nl($output));
204
			}
205
206
			exit ();
207
		} else {
208 1
			return $output;
209
		}
210
	}
211
212 1
	public static function getIncludePaths() {
213 1
		return explode(PATH_SEPARATOR, get_include_path());
214
	}
215
216
	/**
217
	 * @returns ModuleMap
218
	 */
219 1
	public function getCurrentModuleMap() {
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...
220 1
		return $this->getDispatcher()->getCurrentModuleMap();
0 ignored issues
show
Documentation Bug introduced by
The method getCurrentModuleMap does not exist on object<vsc\application\dispatchers\DispatcherA>? 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...
221
	}
222
223 1
	public static function getPaths() {
224 1
		return explode(PATH_SEPARATOR, get_include_path());
225
	}
226
}
227