Skip to content

Commit

Permalink
refactor for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed May 15, 2018
1 parent 2896e1d commit c51be87
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/Commands/RegenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(MediaRepository $mediaRepository, FileManipulator $f

public function handle()
{
if (! $this->confirmToProceed()) {
if (!$this->confirmToProceed()) {
return;
}

Expand Down Expand Up @@ -80,22 +80,31 @@ public function handle()
public function getMediaToBeRegenerated(): Collection
{
$modelType = $this->argument('modelType') ?? '';
$mediaIds = $this->option('ids');
$mediaIds = $this->getMediaIds();

if ($modelType === '' && ! $mediaIds) {
if ($modelType === '' && count($mediaIds) === 0) {
return $this->mediaRepository->all();
}

if ($mediaIds) {
if (! is_array($mediaIds)) {
$mediaIds = explode(',', $mediaIds);
} elseif (count($mediaIds) === 1 && str_contains($mediaIds[0], ',')) {
$mediaIds = explode(',', $mediaIds[0]);
}
if (!count($mediaIds)) {
return $this->mediaRepository->getByModelType($modelType);
}

return $this->mediaRepository->getByIds($mediaIds);
}

protected function getMediaIds(): array
{
$mediaIds = $this->option('ids');

if (!is_array($mediaIds)) {
$mediaIds = explode(',', $mediaIds);
}

return $this->mediaRepository->getByIds($mediaIds);
if (count($mediaIds) === 1 && str_contains($mediaIds[0], ',')) {
$mediaIds = explode(',', $mediaIds[0]);
}

return $this->mediaRepository->getByModelType($modelType);
return $mediaIds;
}
}

0 comments on commit c51be87

Please sign in to comment.