public static function build(int $id = self::DEFAULT_ID, string $name = self::DEFAULT_NAME, Album $album = null)
 {
     if (null === $album) {
         $album = AlbumTestBuilder::build();
     }
     $track = Track::instance($name, $album);
     return $track->setId($id);
 }
 /**
  * @param Command|CreateTrackCommand $command
  *
  * @return mixed
  */
 public function handle(Command $command)
 {
     $album = $this->albumRepository->find($command->albumId());
     $genre = $this->genreRepository->find($command->genreId());
     $mediaType = $this->mediaTypeRepository->find($command->mediaTypeId());
     $playList = $this->playListRepository->find($command->playListId());
     $track = Track::instance($command->name(), $album)->setComposer($command->composer())->setBytes($command->bytes())->setMilliseconds($command->milliseconds())->setGenre($genre)->setMediaType($mediaType)->setUnitPrice($command->unitPrice());
     $this->trackRepository->save($track);
     $playList->addTrack($track);
     $this->playListRepository->save($playList);
     return $this->dataTransformer->transform(CreateTrackCommandResult::instance($track));
 }
 /**
  * @param array $data
  *
  * @return Track
  */
 private function buildEntity(array $data) : Track
 {
     $track = Track::instance($data['name'], Album::instance($data['album']['id'], $data['album']['title']));
     $track->setId($data['id']);
     $track->setGenre(Genre::instance($data['genre']['id'], $data['genre']['name']));
     $track->setMediaType(MediaType::instance($data['mediaType']['id'], $data['mediaType']['name']));
     $track->setComposer($data['composer']);
     return $track;
 }
 /**
  * @param Track $track
  *
  * @return TrackResource
  */
 public function transform(Track $track)
 {
     $trackResource = TrackResource::instance($track->id(), $track->name(), $this->albumToAlbumResourceDataTransformer->transform($track->album()), $this->mediaTypeToMediaTypeResourceDataTransformer->transform($track->mediaType()), $this->genreToGenreResourceDataTransformer->transform($track->genre()));
     $trackResource->setComposer($track->composer())->setMilliseconds($track->milliseconds())->setBytes($track->bytes())->setUnitPrice($track->unitPrice());
     return $trackResource;
 }