/** * process. * * @param Response $values * * @return $this */ private function process($values) { // Create a new albums list. $albumsList = []; // Loop over the response values. foreach ($values as $artistId => $value) { // Decode the json. $fetchedAlbums = json_decode((string) $value->getBody()); // Create an entry even when empty. $albumsList[$artistId] = []; // Process when not empty. if (!empty($fetchedAlbums)) { foreach ($fetchedAlbums->tracks as $albumObject) { // Create a new entity instance and asign value to property. $albumEntity = EntityFactory::newAlbumEntityInstance(); $albumEntity->name = $albumObject->album->name; // Push onto the list. $albumsList[$artistId][] = $albumEntity; } } // Remove dupes. $albumsList[$artistId] = array_unique($albumsList[$artistId], SORT_REGULAR); // The artist entity is currently stored on offset 0. $artistEntity = $this->artistsAlbumsList[$artistId][0]; // Override the offset with Artist and AlbumsList. $this->artistsAlbumsList[$artistId] = [$artistEntity, $albumsList[$artistId]]; } return $this; }
/** * process. * * @param Response $values * * @return $this */ private function process($values) { foreach ($values->artists as $artist) { if ($this->threshold >= self::MAX_THRESHOLD) { continue; } $artistEntity = EntityFactory::newArtistEntityInstance(); $artistEntity->name = $artist->name; $artistEntity->id = $artist->id; $this->artistsAlbumsList[$artistEntity->id] = [$artistEntity]; $this->processedArtistsList[$artistEntity->id] = false; $this->threshold++; } return $this; }