Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make backing type a bool, since it defaults anyway on 1 of 2 options. #971

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('int') ? '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('int', [
'help' => 'Using backed enums with int instead of string as return type',
'boolean' => true,
'short' => 'i',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we need a short option for this as int isn't that long.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it can still be convinient :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

]);

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
Loading