Conditions | 10 |
Paths | 84 |
Total Lines | 35 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
66 | protected function verifyRequestData() |
||
67 | { |
||
68 | if (!is_array($this->requestData)) { |
||
69 | $this->throwInvalidException('root object'); |
||
70 | } |
||
71 | foreach (['jsonapi', 'data'] as $item) { |
||
72 | if (!isset($this->requestData[$item])) { |
||
73 | $this->throwRequiredException($item); |
||
74 | } |
||
75 | } |
||
76 | if (!isset($this->requestData['jsonapi']['version'])) { |
||
77 | $this->throwRequiredException('jsonapi.version'); |
||
78 | } |
||
79 | if ($this->requestData['jsonapi']['version'] != Document::VERSION) { |
||
80 | throw new ApiException( |
||
81 | sprintf('Unsupported JSON API version: %s', $this->requestData['jsonapi']['version']) |
||
82 | ); |
||
83 | } |
||
84 | if (!is_array($this->requestData['data'])) { |
||
85 | $this->throwInvalidException('data'); |
||
86 | } |
||
87 | $key = key($this->requestData['data']); |
||
88 | if (0 === $key) { //multiple data objects |
||
89 | if (!$this->allowMultipleDataObjects) { |
||
90 | throw new ApiException('Multiple data objects not allowed for this endpoint'); |
||
91 | } |
||
92 | foreach ($this->requestData['data'] as $item) { |
||
93 | $this->verifyData($item); |
||
94 | } |
||
95 | } else { // single data object |
||
96 | $this->verifyData($this->requestData['data']); |
||
97 | } |
||
98 | $this->verifyMeta(); |
||
99 | |||
100 | return true; |
||
101 | } |
||
129 |