Skip to content

Commit

Permalink
Make backing type a bool, since it defaults anyway on 1 of 2 options.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Dec 25, 2023
1 parent 9be993d commit bef2b77
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/Command/EnumCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use Cake\Console\Arguments;
use Cake\Console\ConsoleOptionParser;
use InvalidArgumentException;

/**
* Enum code generator.
Expand Down Expand Up @@ -66,7 +65,7 @@ public function template(): string
public function templateData(Arguments $arguments): array
{
$data = parent::templateData($arguments);
$data['backingType'] = $arguments->getOption('backing-type');
$data['backingType'] = $arguments->getOption('integer') ? 'int' : 'string';

return $data;
}
Expand All @@ -83,11 +82,10 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar

$parser->setDescription(
'Bake backed enums for use in models.'
)->addOption('backing-type', [
'help' => 'The return type for the backed enum class',
'default' => 'string',
'choices' => ['string', 'int'],
'short' => 'b',
)->addOption('integer', [
'help' => 'Using backed enums with int instead of string as return type',
'boolean' => true,
'short' => 'i',
]);

return $parser;
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Command/EnumCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testBakeEnum()
public function testBakeEnumBackedInt()
{
$this->generatedFile = APP . 'Model/Enum/FooBar.php';
$this->exec('bake enum FooBar -b int', ['y']);
$this->exec('bake enum FooBar -i', ['y']);

$this->assertExitCode(CommandInterface::CODE_SUCCESS);
$this->assertFileExists($this->generatedFile);
Expand Down

0 comments on commit bef2b77

Please sign in to comment.