Convert CompilerExtensions constants to enum cases

This commit is contained in:
netkas 2024-09-14 00:39:18 -04:00
parent baf11f5cb9
commit d884d0fbda
3 changed files with 8 additions and 11 deletions

View file

@ -22,11 +22,7 @@
namespace ncc\Enums; namespace ncc\Enums;
final class CompilerExtensions enum CompilerExtensions : string
{ {
public const PHP = 'php'; case PHP = 'php';
public const ALL = [
CompilerExtensions::PHP
];
} }

View file

@ -160,7 +160,7 @@
return match (strtolower($this->project_configuration->getProject()->getCompiler()->getExtension())) return match (strtolower($this->project_configuration->getProject()->getCompiler()->getExtension()))
{ {
CompilerExtensions::PHP => match (strtolower($configuration->getBuildType())) CompilerExtensions::PHP->value => match (strtolower($configuration->getBuildType()))
{ {
BuildOutputType::NCC_PACKAGE => (new NccCompiler($this))->build($build_configuration, $options), BuildOutputType::NCC_PACKAGE => (new NccCompiler($this))->build($build_configuration, $options),
BuildOutputType::EXECUTABLE => (new ExecutableCompiler($this))->build($build_configuration, $options), BuildOutputType::EXECUTABLE => (new ExecutableCompiler($this))->build($build_configuration, $options),
@ -258,7 +258,7 @@
{ {
return match ($this->getProjectConfiguration()->getProject()->getCompiler()->getExtension()) return match ($this->getProjectConfiguration()->getProject()->getCompiler()->getExtension())
{ {
CompilerExtensions::PHP => ComponentFileExtensions::PHP, CompilerExtensions::PHP->value => ComponentFileExtensions::PHP,
default => throw new NotSupportedException( default => throw new NotSupportedException(
sprintf('The compiler extension \'%s\' is not supported', $this->getProjectConfiguration()->getProject()->getCompiler()->getExtension()) sprintf('The compiler extension \'%s\' is not supported', $this->getProjectConfiguration()->getProject()->getCompiler()->getExtension())
), ),
@ -485,7 +485,7 @@
throw new IOException(sprintf('Project source directory "%s" was not created', $project_src)); throw new IOException(sprintf('Project source directory "%s" was not created', $project_src));
} }
$project = new ProjectConfiguration\Project(new ProjectConfiguration\Compiler(CompilerExtensions::PHP)); $project = new ProjectConfiguration\Project(new ProjectConfiguration\Compiler(CompilerExtensions::PHP->value));
$assembly = new ProjectConfiguration\Assembly( $assembly = new ProjectConfiguration\Assembly(
Resolver::composerName($composer_json->getName()), Resolver::composerName($composer_json->getName()),
Resolver::composerNameToPackage($composer_json->getName()), Resolver::composerNameToPackage($composer_json->getName()),

View file

@ -77,7 +77,7 @@
/** @noinspection DegradedSwitchInspection */ /** @noinspection DegradedSwitchInspection */
switch($extension) switch($extension)
{ {
case CompilerExtensions::PHP: case CompilerExtensions::PHP->value:
if($minimum_version === null) if($minimum_version === null)
{ {
@ -185,7 +185,8 @@
} }
/** @noinspection InArrayMissUseInspection */ /** @noinspection InArrayMissUseInspection */
if(!in_array($this->extension, CompilerExtensions::ALL, true)) // TODO: Fix this, not a proper use of cases()
if(!in_array($this->extension, CompilerExtensions::cases(), true))
{ {
throw new NotSupportedException('The compiler extension \'' . $this->extension . '\' is not supported'); throw new NotSupportedException('The compiler extension \'' . $this->extension . '\' is not supported');
} }