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.

RESTProcessorA   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 6

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
dl 0
loc 60
ccs 26
cts 30
cp 0.8667
rs 10
c 0
b 0
f 0
wmc 12
lcom 3
cbo 6

10 Methods

Rating   Name   Duplication   Size   Complexity  
handleGet() 0 1 ?
handleHead() 0 1 ?
handlePost() 0 1 ?
handlePut() 0 1 ?
handleDelete() 0 1 ?
A getValidRequestMethods() 0 3 1
A getValidContentTypes() 0 3 1
A validRequestMethod() 0 3 1
A validContentType() 0 3 1
B handleRequest() 0 27 8
1
<?php
2
/**
3
 * A processor for RESTful calls
4
 *
5
 * @package application/processors
6
 * @author marius orcsik <[email protected]>
7
 * @date 2013.10.04
8
 */
9
namespace vsc\rest\application\processors;
10
11
use vsc\application\processors\ProcessorA;
12
use vsc\infrastructure\vsc;
13
use vsc\presentation\requests\ContentType;
14
use vsc\presentation\requests\HttpRequestA;
15
use vsc\presentation\requests\HttpRequestTypes;
16
use vsc\presentation\requests\RawHttpRequest;
17
use vsc\presentation\responses\ExceptionResponseError;
18
use vsc\presentation\responses\HttpResponseType;
19
20
abstract class RESTProcessorA extends ProcessorA {
21
	protected $validRequestMethods = array( );
22
23
	public function getValidRequestMethods() {
24
		return $this->validRequestMethods;
25
	}
26
27
	protected $validContentTypes = array('*/*');
28
29 1
	public function getValidContentTypes() {
30 1
		return $this->validContentTypes;
31
	}
32
33 2
	public function validRequestMethod($sRequestMethod) {
34 2
		return (in_array($sRequestMethod, $this->getValidRequestMethods()));
35
	}
36
37 28
	public function validContentType($sContentType) {
38 28
		return ContentType::isAccepted($sContentType, $this->getValidContentTypes());
39
	}
40
41
	abstract public function handleGet(HttpRequestA $oRequest);
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...
42
	abstract public function handleHead(HttpRequestA $oRequest);
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...
43
	abstract public function handlePost(HttpRequestA $oRequest);
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...
44
	abstract public function handlePut(RawHttpRequest $oRequest);
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...
45
	abstract public function handleDelete(RawHttpRequest $oRequest);
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...
46
47
	/**
48
	 * @param HttpRequestA $oRequest
49
	 * @return \vsc\domain\models\ModelA
50
	 * @throws \vsc\presentation\responses\ExceptionResponseError
51
	 */
52 6
	public function handleRequest(HttpRequestA $oRequest) {
53 6
		if (!$oRequest->isGet() && !RawHttpRequest::isValid($oRequest)) {
54
			$oRequest = new RawHttpRequest();
55
			vsc::getEnv()->setHttpRequest($oRequest);
56
		}
57
58 6
		switch ($oRequest->getHttpMethod()) {
59 6
		case HttpRequestTypes::GET:
60 1
			$oModel = $this->handleGet($oRequest);
61 1
			break;
62 5
		case HttpRequestTypes::HEAD:
63 1
			$oModel = $this->handleHead($oRequest);
64 1
			break;
65 4
		case HttpRequestTypes::POST:
66 1
			$oModel = $this->handlePost($oRequest);
67 1
			break;
68 3
		case HttpRequestTypes::PUT:
69 1
			$oModel = $this->handlePut($oRequest);
0 ignored issues
show
Compatibility introduced by
$oRequest of type object<vsc\presentation\requests\HttpRequestA> is not a sub-type of object<vsc\presentation\requests\RawHttpRequest>. It seems like you assume a child class of the class vsc\presentation\requests\HttpRequestA to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
70 1
			break;
71 2
		case HttpRequestTypes::DELETE:
72 1
			$oModel = $this->handleDelete($oRequest);
0 ignored issues
show
Compatibility introduced by
$oRequest of type object<vsc\presentation\requests\HttpRequestA> is not a sub-type of object<vsc\presentation\requests\RawHttpRequest>. It seems like you assume a child class of the class vsc\presentation\requests\HttpRequestA to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
73 1
			break;
74
		default:
75 1
			throw new ExceptionResponseError('Method [' . $oRequest->getHttpMethod() . '] is unavailable.', HttpResponseType::METHOD_NOT_ALLOWED);
76
		}
77 5
		return $oModel;
78
	}
79
}
80