diff --git a/src/Console/Command/BuildCommand.php b/src/Console/Command/BuildCommand.php index 5c511ce..0748461 100644 --- a/src/Console/Command/BuildCommand.php +++ b/src/Console/Command/BuildCommand.php @@ -32,6 +32,11 @@ final class BuildCommand extends AbstractCommand workingDir: $workingDir, ))->getLanguage(); + assert( + assertion: ProjectLanguage::isValid($language), + description: sprintf('%s is not a supported language.', $language), + ); + // Attempt to prepopulate some of the options, such as the project type // based on its dependencies. // TODO: move this logic to a service so it can be tested. @@ -60,6 +65,11 @@ final class BuildCommand extends AbstractCommand // with the option value if there is one. $projectType = $input->getOption('type') ?? $projectType; + assert( + assertion: ProjectType::isValid($projectType), + description: sprintf('%s is not a supported project type.', $projectType), + ); + $isDockerCompose = $this->filesystem->exists($workingDir . '/docker-compose.yaml'); switch ($language) { diff --git a/src/Console/Command/InstallCommand.php b/src/Console/Command/InstallCommand.php index eddd2a3..7645e32 100644 --- a/src/Console/Command/InstallCommand.php +++ b/src/Console/Command/InstallCommand.php @@ -32,6 +32,11 @@ final class InstallCommand extends AbstractCommand ))->getLanguage(); } + assert( + assertion: ProjectLanguage::isValid($language), + description: sprintf('%s is not a supported language.', $language), + ); + // TODO: Composer in Docker Compose? $process = Process::create( args: explode(separator: ' ', string: strval($args)), diff --git a/src/Console/Command/PackageInstallCommand.php b/src/Console/Command/PackageInstallCommand.php index 7677f6b..860f534 100644 --- a/src/Console/Command/PackageInstallCommand.php +++ b/src/Console/Command/PackageInstallCommand.php @@ -39,6 +39,11 @@ final class PackageInstallCommand extends AbstractCommand workingDir: $workingDir, ))->getLanguage(); + assert( + assertion: ProjectLanguage::isValid($language), + description: sprintf('%s is not a supported language.', $language), + ); + switch ($language) { case ProjectLanguage::PHP->value: $process = Process::create( diff --git a/src/Console/Command/RunCommand.php b/src/Console/Command/RunCommand.php index 968b3c6..882074c 100644 --- a/src/Console/Command/RunCommand.php +++ b/src/Console/Command/RunCommand.php @@ -32,6 +32,11 @@ final class RunCommand extends AbstractCommand workingDir: $workingDir, ))->getLanguage(); + assert( + assertion: ProjectLanguage::isValid($language), + description: sprintf('%s is not a supported language.', $language), + ); + // Attempt to prepopulate some of the options, such as the project type // based on its dependencies. // TODO: move this logic to a service so it can be tested. @@ -60,6 +65,11 @@ final class RunCommand extends AbstractCommand // with the option value if there is one. $projectType = $input->getOption('type') ?? $projectType; + assert( + assertion: ProjectType::isValid($projectType), + description: sprintf('%s is not a supported project type.', $projectType), + ); + $filesystem = new Filesystem(); $isDockerCompose = $filesystem->exists($workingDir . '/docker-compose.yaml'); diff --git a/src/Enum/ProjectLanguage.php b/src/Enum/ProjectLanguage.php index f0df04c..39bd65d 100644 --- a/src/Enum/ProjectLanguage.php +++ b/src/Enum/ProjectLanguage.php @@ -8,4 +8,16 @@ enum ProjectLanguage: string { case JavaScript = 'javascript'; case PHP = 'php'; + + /** + * @param non-empty-string $language + */ + public static function isValid(string $language): bool + { + return in_array( + haystack: array_column(self::cases(), 'value'), + needle: $language, + strict: true, + ); + } } diff --git a/src/Enum/ProjectType.php b/src/Enum/ProjectType.php index f5f77b2..ae593b7 100644 --- a/src/Enum/ProjectType.php +++ b/src/Enum/ProjectType.php @@ -13,4 +13,16 @@ enum ProjectType: string case Drupal = 'drupal'; case Sculpin = 'sculpin'; case Symfony = 'symfony'; + + /** + * @param non-empty-string $projectType + */ + public static function isValid(string $projectType): bool + { + return in_array( + haystack: array_column(self::cases(), 'value'), + needle: $projectType, + strict: true, + ); + } }