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 ( 2f0bc6...b62162 )
by Marius
04:15
created

vsc::getSiteMap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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 Object {
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))) {
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...
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() {
0 ignored issues
show
Coding Style introduced by
getHttpRequest uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
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) && 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() {
0 ignored issues
show
Coding Style introduced by
isDevelopment uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
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 1
	public static function d() {
0 ignored issues
show
Coding Style introduced by
d uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
169 1
		$aRgs = func_get_args();
170
171 1
		$output = '';
172 1
		for ($i = 0; $i < ob_get_level(); $i++) {
173
			// cleaning the buffers
174 1
			ob_end_clean();
175
		}
176
177 1
		if (!self::isCLi() && self::getEnv()->getHttpRequest()->accepts('application/json')) {
178
			$output = json_encode($aRgs);
179 1
		} elseif (self::isCLi() || self::getEnv()->getHttpRequest()->accepts('text/html')) {
180 1
			foreach ($aRgs as $object) {
181 1
				ob_start();
182 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...
183 1
				$output .= ob_get_clean();
184
185 1
				if (!self::isCli()) {
186 1
					$output .= '<hr/>' . "\n";
187
				}
188
			}
189
		}
190
191 1
		if (!stristr($_SERVER['PHP_SELF'], 'phpunit')) {
192
			ob_start();
193
			debug_print_backtrace();
194
			$output .= ob_get_clean();
195
196
			if (self::isCLi() || self::getEnv()->getHttpRequest()->accepts('application/json')) {
197
				echo StringUtils::stripTags(StringUtils::br2nl($output));
198
			} elseif (self::getEnv()->getHttpRequest()->accepts('text/html')) {
199
				echo '<pre>' . $output . '</pre>';
200
			} else {
201
				echo StringUtils::stripTags(StringUtils::br2nl($output));
202
			}
203
204
			exit ();
0 ignored issues
show
Coding Style Compatibility introduced by
The method d() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
205
		} else {
206 1
			return $output;
207
		}
208
	}
209
210 1
	public static function getIncludePaths() {
211 1
		return explode(PATH_SEPARATOR, get_include_path());
212
	}
213
214
	/**
215
	 * @returns ModuleMap
216
	 */
217 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...
218 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...
219
	}
220
221 1
	public static function getPaths() {
222 1
		return explode(PATH_SEPARATOR, get_include_path());
223
	}
224
}
225