Skip to content

Commit

Permalink
Two traits
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor committed Dec 27, 2024
1 parent e64b833 commit 6db5d2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Run PHPStan
run: |
composer require --dev pestphp/pest
phpstan
phpstan analyze -v
- name: Run Composer Dependency Analyser
run: |
Expand Down
14 changes: 8 additions & 6 deletions src/EnumConcern.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ trait EnumConcern
{
/**
* Check if the current enum is a BackedEnum.
*
* @ phpstan-assert-if-true \BackedEnum $this
*/
public static function isBackedEnum(): bool
{
Expand Down Expand Up @@ -50,18 +52,18 @@ public static function names(): Collection
*/
public static function toArray(): array
{
/** @var array<string, string|int> $result */
$result = self::toKeyValueCollection()->toArray();

return $result;
return array_combine(
array_column(self::cases(), 'name'),
array_column(self::cases(), 'value')
);
}

/**
* Returns a Laravel Collection instance containing all enum cases.
*/
public static function toCollection(): Collection
{
return collect(self::cases());
return new Collection(self::cases());
}

/**
Expand Down Expand Up @@ -120,7 +122,7 @@ public static function hasValue(string|int $value): bool
*/
public static function hasName(string $name): bool
{
return self::names()->contains($name);
return defined("self::{$name}");
}

/**
Expand Down

0 comments on commit 6db5d2c

Please sign in to comment.