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 ( 290674...0f9d71 )
by Marius
14:11 queued 07:19
created

RPCProcessorA::callRPCMethod()   C

Complexity

Conditions 7
Paths 10

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 12.1068

Importance

Changes 0
Metric Value
cc 7
eloc 19
nc 10
nop 0
dl 0
loc 29
ccs 9
cts 17
cp 0.5294
crap 12.1068
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package presentation
4
 * @subpackage processors
5
 * @author marius orcsik <[email protected]>
6
 * @date 12.08.25
7
 */
8
namespace vsc\application\processors;
9
10
use vsc\domain\models\JsonRPCRequest;
11
use vsc\domain\models\JsonRPCResponse;
12
use vsc\infrastructure\vsc;
13
use vsc\presentation\requests\HttpRequestA;
14
use vsc\presentation\responses\ExceptionResponseError;
15
use vsc\Exception;
16
17
abstract class RPCProcessorA extends ProcessorA {
18
	private $oRequest;
19
	private $oResponse;
20
	protected $oInterface;
21
22
	public function __construct() {
23
		$this->oRequest		= new JsonRPCRequest(vsc::getEnv()->getHttpRequest());
24
		$this->oResponse	= new JsonRPCResponse();
25
	}
26
27 1
	public function init() {
28 1
		$this->oResponse->id = $this->oRequest->id;
29
// 		if (!$oRequest->accepts('application/json')) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
30
// 			// user-agent doesn't understand json
31
// 		}
32 1
	}
33
34 1
	public function getRequest() {
35 1
		return $this->oRequest;
36
	}
37
38 1
	public function getResponse() {
39 1
		return $this->oResponse;
40
	}
41
42
	abstract public function getRPCInterface($sNameSpace = null);
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
44 1
	public function hasRPCMethod($oInterface, $sMethod) {
45 1
		if (empty ($sMethod) || empty ($oInterface)) {
46
			return false;
47
		}
48
49 1
		$oReflectedInterface = new \ReflectionObject($oInterface);
50 1
		if ($oReflectedInterface->hasMethod($sMethod)) {
51
			/* @var $oReflectedMethod \ReflectionMethod */
52 1
			$oReflectedMethod = $oReflectedInterface->getMethod($sMethod);
53 1
			return $oReflectedMethod->isPublic();
54
		}
55 1
		return false;
56
	}
57
58 1
	public function callRPCMethod() {
59 1
		$sRawMethod = $this->oRequest->method;
60
61 1
		if (strpos($sRawMethod, '.') !== false) {
62
			list($sNameSpace, $sMethod) = explode('.', $sRawMethod);
63
		} else {
64 1
			$sMethod = $sRawMethod;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
65 1
			$sNameSpace = 'wp';
66
		}
67
68 1
		$oInterface = $this->getRPCInterface($sNameSpace);
69 1
		if (!$this->hasRPCMethod($oInterface, $sMethod)) {
70 1
			$this->oResponse->error = 'Invalid RPC request: method [' . var_export($sMethod, true) . '] does not exist';
71
		} else {
72
			if (is_null($this->oRequest->params) || !is_array($this->oRequest->params)) {
73
				throw new ExceptionResponseError('Invalid RPC request: missing parameters');
74
			}
75
76
			$oReflectedInterface = new \ReflectionObject($oInterface);
77
			if ($oReflectedInterface->hasMethod($sMethod)) {
78
				/* @var $oReflectedMethod \ReflectionMethod */
79
				$oReflectedMethod = $oReflectedInterface->getMethod($sMethod);
80
				if ($oReflectedMethod->isPublic()) {
81
					return $oReflectedMethod->invokeArgs($oInterface, $this->oRequest->params);
82
				}
83
			}
84
		}
85 1
		return null;
86
	}
87
88 1
	public function handleRequest(HttpRequestA $oHttpRequest) {
89
		try {
90 1
			$this->oResponse->result = $this->callRPCMethod();
91
		} catch (ExceptionResponseError $e) {
92
93
			$oError = vsc::getEnv()->getHttpResponse();
94
			$oError->setStatus($e->getErrorCode());
95
			$this->getMap()->setResponse($oError);
0 ignored issues
show
Documentation Bug introduced by
The method setResponse 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...
96
			$this->oResponse->error = $e->getMessage();
97
98
		} catch (Exception $e) {
99
			$oError = vsc::getEnv()->getHttpResponse();
100
			$oError->setStatus(500);
101
			$this->getMap()->setResponse($oError);
0 ignored issues
show
Documentation Bug introduced by
The method setResponse 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...
102
			$this->oResponse->error = $e->getMessage();
103
104
		}
105 1
		return $this->oResponse;
106
	}
107
}
108