Skip to content

Commit

Permalink
Remove leading backslash in class names passed to `php artisan enum:t…
Browse files Browse the repository at this point in the history
…o-native`
  • Loading branch information
spawnia committed Aug 31, 2023
1 parent 255a509 commit 97cbf47
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## 6.6.3

### Fixed

- Remove leading backslash in class names passed to `php artisan enum:to-native`

## 6.6.2

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Make sure you meet the following requirements:
Depending on the size of your project, you may choose to migrate all enums at once,
or migrate just a couple or one enum at a time.
- Convert all enums at once: `php artisan enum:to-native`
- Pass the fully qualified class name of an enum to limit the conversion: `php artisan enum:to-native "\App\Enums\UserType"`
- Pass the fully qualified class name of an enum to limit the conversion: `php artisan enum:to-native "App\Enums\UserType"`

This is necessary if any enums are used during the bootstrap phase of Laravel,
the conversion of their usages interferes with Larastan and prevents a second run of Rector from working.
Expand Down
3 changes: 3 additions & 0 deletions src/Commands/EnumToNativeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ protected function getArguments(): array
public function handle(): int
{
$class = $this->argument('class');
if ($class) {
$class = ltrim($class, '\\');
}

$env = [
self::TO_NATIVE_CLASS_ENV => $class ?? Enum::class,
Expand Down
1 change: 1 addition & 0 deletions src/Rules/EnumValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function passes($attribute, $value): bool
assert(is_int($enumValue), 'Flagged enum values must be int');
$value &= ~$enumValue;
}

// All bits should be unset
return $value === 0;
}
Expand Down

0 comments on commit 97cbf47

Please sign in to comment.