diff --git a/src/FileSystem.php b/src/FileSystem.php index e325b36..2c55272 100644 --- a/src/FileSystem.php +++ b/src/FileSystem.php @@ -65,13 +65,13 @@ class FileSystem { $path = static::normalizePath($path); if (!file_exists($path)) { - throw new DirectoryNotExistsException("output directory is not exist: $path"); + throw new DirectoryNotExistsException("directory does not exist: $path"); } if (!is_readable($path)) { - throw new DirectoryIsNotReadableException("output directory permissions are not valid: $path"); + throw new DirectoryIsNotReadableException("directory permissions are not valid: $path"); } if (!is_writable($path)) { - throw new DirectoryIsNotWriteableException("output directory permissions are not valid: $path"); + throw new DirectoryIsNotWriteableException("directory permissions are not valid: $path"); } return true; } diff --git a/src/Processor.php b/src/Processor.php index c79c00e..7450d29 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -27,7 +27,7 @@ class Processor /** * @var string[] Paths to collection files */ - protected array $collectionPaths; + protected array $collectionPaths = []; /** * @var string Output path where to put results in @@ -52,7 +52,7 @@ class Processor /** * @var object[] Collections that will be converted into choosen formats */ - protected array $collections; + protected array $collections = []; /** * Constructor @@ -80,7 +80,7 @@ class Processor switch ($arg) { case '-f': case '--file': - $path = $this->argv[$idx + 1]; + $path = FileSystem::normalizePath($this->argv[$idx + 1]); if (empty($path) || !str_ends_with($path, '.json') || !file_exists($path) || !is_readable($path)) { throw new InvalidArgumentException('a valid json-file path is expected for -f (--file)'); } @@ -99,13 +99,11 @@ class Processor throw new InvalidArgumentException('a directory path is expected for -d (--dir)'); } $path = $this->argv[$idx + 1]; - if (FileSystem::checkDir($path)) { - $files = array_filter( - FileSystem::dirContents($path), - static fn($filename) => str_ends_with($filename, '.json') - ); - $this->collectionPaths = array_unique(array_merge($this?->collectionPaths ?? [], $files)); - } + $files = array_filter( + FileSystem::dirContents($path), + static fn($filename) => str_ends_with($filename, '.json') + ); + $this->collectionPaths = array_unique(array_merge($this?->collectionPaths ?? [], $files)); break; case '-p': case '--preserve': @@ -128,6 +126,9 @@ class Processor die(implode(PHP_EOL, $this->usage()) . PHP_EOL); } } + if (empty($this->collectionPaths)) { + throw new InvalidArgumentException('there are no collections to convert'); + } if (empty($this->formats)) { $this->formats = [ConvertFormat::Http->name => ConvertFormat::Http]; }