| Conditions | 8 |
| Paths | 4 |
| Total Lines | 83 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 158 | protected function getBooksDependencies(\SimpleXMLElement $data, \SimpleXMLElement $book) |
||
| 159 | { |
||
| 160 | // Book attributes |
||
| 161 | $bookAttributes = $this->getSimpleXmlElementAttributesAsArray($book); |
||
| 162 | |||
| 163 | // Series attributes |
||
| 164 | $series = $book->{'series'}[0]; |
||
| 165 | $seriesAttributes = $this->getSimpleXmlElementAttributesAsArray($series); |
||
| 166 | |||
| 167 | // Publish attributes |
||
| 168 | $publish = $book->{'publish'}[0]; |
||
| 169 | $publishAttributes = $this->getSimpleXmlElementAttributesAsArray($publish); |
||
| 170 | |||
| 171 | // Editor attributes |
||
| 172 | $releaseEditor = $book->{'editor'}[0]; |
||
| 173 | $releaseEditorAttributes = $this->getSimpleXmlElementAttributesAsArray($releaseEditor); |
||
| 174 | |||
| 175 | // Categories data |
||
| 176 | $categories = $data->xpath('//information/types/type[@code="'.$bookAttributes['type'].'"]'); |
||
| 177 | $categoryAttributes = $this->getSimpleXmlElementAttributesAsArray(reset($categories)); |
||
| 178 | |||
| 179 | // Releases data |
||
| 180 | $releases = array(); |
||
| 181 | foreach (array_keys($releaseEditorAttributes) as $release) { |
||
| 182 | $releaseNode = $book->$release; |
||
| 183 | |||
| 184 | // Categories data |
||
| 185 | $editor = $data->xpath('//information/editors/editor[@code="'.$releaseEditorAttributes[$release].'"]'); |
||
| 186 | $editorAttributes = $this->getSimpleXmlElementAttributesAsArray(reset($editor)); |
||
| 187 | |||
| 188 | $releases[] = new $this->classes['release']( |
||
| 189 | array( |
||
| 190 | 'title' => (string) $book->{'title'}, |
||
| 191 | 'editor' => new $this->classes['editor']( |
||
| 192 | $this->renameArrayKeys( |
||
| 193 | $editorAttributes, |
||
| 194 | array('code' => 'id', 'lang' => 'preferredLanguage') |
||
| 195 | ) |
||
| 196 | ), |
||
| 197 | 'publicationDate' => isset($publishAttributes[$release]) |
||
| 198 | ? $this->transformToDateTime($publishAttributes[$release]) |
||
| 199 | : null, |
||
| 200 | 'language' => new $this->classes['language']( |
||
| 201 | array( |
||
| 202 | 'id' => $editorAttributes['lang'], |
||
| 203 | 'name' => $editorAttributes['lang'], |
||
| 204 | ) |
||
| 205 | ), |
||
| 206 | 'owner' => new $this->classes['owner']( |
||
| 207 | array( |
||
| 208 | 'nbCopies' => isset($releaseNode['copies']) ? (int) $releaseNode['copies'] : null, |
||
| 209 | 'nbReadings' => isset($releaseNode['readings']) ? (int) $releaseNode['readings'] : null, |
||
| 210 | ) |
||
| 211 | ), |
||
| 212 | 'format' => new $this->classes['format'](), |
||
| 213 | 'series' => new $this->classes['series']( |
||
| 214 | null !== $series |
||
| 215 | ? array( |
||
| 216 | 'title' => (string) $series, |
||
| 217 | 'bookId' => isset($seriesAttributes['number']) ? $seriesAttributes['number'] : null, |
||
| 218 | ) |
||
| 219 | : array() |
||
| 220 | ), |
||
| 221 | ) |
||
| 222 | ); |
||
| 223 | } |
||
| 224 | |||
| 225 | $authors = array(); |
||
| 226 | foreach (explode(',', (string) $book->{'author'}) as $author) { |
||
| 227 | $authors[] = new $this->classes['author'](array('name' => trim($author))); |
||
| 228 | } |
||
| 229 | |||
| 230 | return array( |
||
| 231 | 'category' => new $this->classes['category']( |
||
| 232 | array( |
||
| 233 | 'id' => $bookAttributes['type'], |
||
| 234 | 'name' => $categoryAttributes['name'], |
||
| 235 | ) |
||
| 236 | ), |
||
| 237 | 'authors' => $authors, |
||
| 238 | 'releases' => $releases, |
||
| 239 | ); |
||
| 240 | } |
||
| 241 | |||
| 255 |