| Conditions | 4 |
| Paths | 4 |
| Total Lines | 35 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 21 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | 2 | protected function run( |
|
| 24 | ServerRequestInterface $request, |
||
| 25 | JsonEnabledResponseInterface $response, |
||
| 26 | array $args |
||
| 27 | ): ResponseInterface { |
||
| 28 | 2 | $albumId = (int) ($args['albumId'] ?? 0); |
|
| 29 | |||
| 30 | 2 | $album = $this->albumRepository->find($albumId); |
|
| 31 | |||
| 32 | 2 | if ($album === null) { |
|
| 33 | 1 | return $response->withStatus(Http::NOT_FOUND); |
|
| 34 | } |
||
| 35 | |||
| 36 | 1 | $discsData = []; |
|
| 37 | |||
| 38 | 1 | foreach ($album->getDiscs() as $disc) { |
|
| 39 | 1 | $songData = []; |
|
| 40 | |||
| 41 | 1 | foreach ($disc->getSongs() as $song) { |
|
| 42 | 1 | $songData[] = $this->resultItemFactory->createSongListItem( |
|
| 43 | 1 | $song, |
|
| 44 | 1 | $album |
|
| 45 | 1 | ); |
|
| 46 | } |
||
| 47 | |||
| 48 | 1 | $discsData[] = [ |
|
| 49 | 1 | 'id' => $disc->getId(), |
|
| 50 | 1 | 'songs' => $songData, |
|
| 51 | 1 | 'length' => $disc->getLength(), |
|
| 52 | 1 | 'number' => $disc->getNumber(), |
|
| 53 | 1 | ]; |
|
| 54 | } |
||
| 55 | |||
| 56 | 1 | return $response->withJson( |
|
| 57 | 1 | ['items' => $discsData] |
|
| 58 | 1 | ); |
|
| 61 |