| Conditions | 10 |
| Paths | 14 |
| Total Lines | 35 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 48 | protected function verifyRequestData() |
||
| 49 | { |
||
| 50 | if (!is_array($this->requestData)) { |
||
| 51 | throw new HttpException(sprintf(self::MSG_TPL_INVALID, 'root object')); |
||
| 52 | } |
||
| 53 | foreach (['jsonapi', 'data'] as $item) { |
||
| 54 | if (!isset($this->requestData[$item])) { |
||
| 55 | throw new HttpException(sprintf(self::MSG_TPL_REQUIRED, $item)); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | if (!isset($this->requestData['jsonapi']['version'])) { |
||
| 59 | throw new HttpException(sprintf(self::MSG_TPL_REQUIRED, 'jsonapi.version')); |
||
| 60 | } |
||
| 61 | if ($this->requestData['jsonapi']['version'] != Structure::VERSION) { |
||
| 62 | throw new HttpException( |
||
| 63 | sprintf('Unsupported JSON API version: %s', $this->requestData['jsonapi']['version']) |
||
| 64 | ); |
||
| 65 | } |
||
| 66 | if (!is_array($this->requestData['data'])) { |
||
| 67 | throw new HttpException(sprintf(self::MSG_TPL_INVALID, 'data')); |
||
| 68 | } |
||
| 69 | $key = key($this->requestData['data']); |
||
| 70 | if (0 === $key) { //multiple data objects |
||
| 71 | if (!$this->allowMultipleDataObjects) { |
||
| 72 | throw new HttpException('Multiple data objects not allowed for this endpoint'); |
||
| 73 | } |
||
| 74 | foreach ($this->requestData['data'] as $item) { |
||
| 75 | $this->verifyData($item); |
||
| 76 | } |
||
| 77 | } else { // single data object |
||
| 78 | $this->verifyData($this->requestData['data']); |
||
| 79 | } |
||
| 80 | $this->verifyMeta(); |
||
| 81 | |||
| 82 | return true; |
||
| 83 | } |
||
| 111 |