Conditions | 11 |
Paths | 168 |
Total Lines | 40 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | 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 |
||
88 | protected function verifyRequestData(): bool |
||
89 | { |
||
90 | if (!\is_array($this->requestData)) { |
||
|
|||
91 | $this->throwInvalidException('root object'); |
||
92 | } |
||
93 | if (!$this->requestData) { // check if empty array, could also mean the json vas invalid |
||
94 | $this->throwRequiredException('root object'); |
||
95 | } |
||
96 | foreach (['jsonapi', 'data'] as $item) { |
||
97 | if (isset($this->requestData[$item])) { |
||
98 | continue; |
||
99 | } |
||
100 | |||
101 | $this->throwRequiredException($item); |
||
102 | } |
||
103 | if (!isset($this->requestData['jsonapi']['version'])) { |
||
104 | $this->throwRequiredException('jsonapi.version'); |
||
105 | } |
||
106 | if (Document::VERSION !== $this->requestData['jsonapi']['version']) { |
||
107 | throw new ApiException( |
||
108 | \sprintf('Unsupported JSON API version: %s', $this->requestData['jsonapi']['version']), |
||
109 | ); |
||
110 | } |
||
111 | if (!\is_array($this->requestData['data'])) { |
||
112 | $this->throwInvalidException('data'); |
||
113 | } |
||
114 | $key = \key($this->requestData['data']); |
||
115 | if (0 === $key) { //multiple data objects |
||
116 | if (!$this->allowMultipleDataObjects) { |
||
117 | throw new ApiException('Multiple data objects not allowed for this endpoint'); |
||
118 | } |
||
119 | foreach ($this->requestData['data'] as $item) { |
||
120 | $this->verifyData($item); |
||
121 | } |
||
122 | } else { // single data object |
||
123 | $this->verifyData($this->requestData['data']); |
||
124 | } |
||
125 | $this->verifyMeta(); |
||
126 | |||
127 | return true; |
||
128 | } |
||
162 |