| Conditions | 7 |
| Paths | 7 |
| Total Lines | 57 |
| Code Lines | 35 |
| 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 |
||
| 46 | public function index() |
||
| 47 | { |
||
| 48 | // Only allow POST requests |
||
| 49 | $this->request->allowMethod(['post']); |
||
| 50 | |||
| 51 | // Validate request |
||
| 52 | if (($statusCode = $this->_validateRequest($this->request)) !== 201) { |
||
| 53 | Log::error( |
||
| 54 | 'Could not validate the request. Sending a ' |
||
| 55 | . $statusCode . ' response.' |
||
| 56 | ); |
||
| 57 | |||
| 58 | // Send a response |
||
| 59 | $this->auto_render = false; |
||
| 60 | $this->response->statusCode($statusCode); |
||
| 61 | |||
| 62 | return $this->response; |
||
| 63 | } |
||
| 64 | |||
| 65 | $issuesData = $this->request->input('json_decode', true); |
||
| 66 | $eventAction = $issuesData['action']; |
||
| 67 | $issueNumber = $issuesData['issue'] ? $issuesData['issue']['number'] : ''; |
||
| 68 | |||
| 69 | if ($eventAction === 'closed' |
||
| 70 | || $eventAction === 'opened' |
||
| 71 | || $eventAction === 'reopened' |
||
| 72 | ) { |
||
| 73 | $status = $this->_getAppropriateStatus($eventAction); |
||
| 74 | |||
| 75 | if (($reportsUpdated = $this->Reports->setLinkedReportStatus($issueNumber, $status)) > 0) { |
||
| 76 | Log::debug( |
||
| 77 | $reportsUpdated . ' linked reports to issue number ' |
||
| 78 | . $issueNumber . ' were updated according to recieved action ' |
||
| 79 | . $eventAction |
||
| 80 | ); |
||
| 81 | } else { |
||
| 82 | Log::info( |
||
| 83 | 'No linked report found for issue number \'' . $issueNumber |
||
| 84 | . '\'. Ignoring the event.' |
||
| 85 | ); |
||
| 86 | $statusCode = 204; |
||
| 87 | print_r('asd ' . $issueNumber . ' ' . $eventAction); |
||
| 88 | } |
||
| 89 | } else { |
||
| 90 | Log::info( |
||
| 91 | 'Recieved a webhook event for action \'' . $eventAction |
||
| 92 | . '\' on issue number ' . $issueNumber . '. Ignoring the event.' |
||
| 93 | ); |
||
| 94 | $statusCode = 204; |
||
| 95 | } |
||
| 96 | |||
| 97 | // Send a response |
||
| 98 | $this->auto_render = false; |
||
| 99 | $this->response->statusCode($statusCode); |
||
| 100 | |||
| 101 | return $this->response; |
||
| 102 | } |
||
| 103 | |||
| 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.