| Conditions | 8 |
| Paths | 12 |
| Total Lines | 59 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 112 | protected function _validateRequest($request) |
||
| 113 | { |
||
| 114 | // Default $statusCode |
||
| 115 | $statusCode = 201; |
||
| 116 | |||
| 117 | $userAgent = $request->getHeaderLine('User-Agent'); |
||
| 118 | $eventType = $request->getHeaderLine('X-GitHub-Event'); |
||
| 119 | |||
| 120 | $recievedHashHeader = $request->getHeaderLine('X-Hub-Signature'); |
||
| 121 | $algo = ''; |
||
| 122 | $recievedHash = ''; |
||
| 123 | if ($recievedHashHeader !== NULL) { |
||
| 124 | $parts = explode('=', $recievedHashHeader); |
||
| 125 | if (count($parts) > 1) { |
||
| 126 | $algo = $parts[0]; |
||
| 127 | $recievedHash = $parts[1]; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | $expectedHash = $this->_getHash(file_get_contents('php://input'), $algo); |
||
| 132 | |||
| 133 | if ($userAgent !== NULL && strpos($userAgent, 'GitHub-Hookshot') !== 0) { |
||
| 134 | // Check if the User-agent is Github |
||
| 135 | // Otherwise, Send a '403: Forbidden' |
||
| 136 | |||
| 137 | Log::error( |
||
| 138 | 'Invalid User agent: ' . $userAgent |
||
| 139 | . '. Ignoring the event.' |
||
| 140 | ); |
||
| 141 | $statusCode = 403; |
||
| 142 | |||
| 143 | return $statusCode; |
||
| 144 | } elseif ($eventType !== NULL && $eventType !== 'issues') { |
||
| 145 | // Check if the request is based on 'issues' event |
||
| 146 | // Otherwise, Send a '400: Bad Request' |
||
| 147 | |||
| 148 | Log::error( |
||
| 149 | 'Unexpected event type: ' . $eventType |
||
| 150 | . '. Ignoring the event.' |
||
| 151 | ); |
||
| 152 | $statusCode = 400; |
||
| 153 | |||
| 154 | return $statusCode; |
||
| 155 | } elseif ($recievedHash !== $expectedHash) { |
||
| 156 | // Check if hash matches |
||
| 157 | // Otherwise, Send a '401: Unauthorized' |
||
| 158 | |||
| 159 | Log::error( |
||
| 160 | 'Recieved hash ' . $recievedHash . ' does not match ' |
||
| 161 | . ' expected hash ' . $expectedHash |
||
| 162 | . '. Ignoring the event.' |
||
| 163 | ); |
||
| 164 | $statusCode = 401; |
||
| 165 | |||
| 166 | return $statusCode; |
||
| 167 | } |
||
| 168 | |||
| 169 | return $statusCode; |
||
| 170 | } |
||
| 171 | |||
| 216 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.