Skip to content

Modernize codebase #12

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/EnumNames.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Lazerg\LaravelEnumPro;

Expand All @@ -13,8 +14,7 @@ trait EnumNames
*/
public static function names(): Collection
{
return collect(self::cases())
->map(fn($case) => $case->name);
return collect(self::cases())->pluck('name');
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/EnumOptions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Lazerg\LaravelEnumPro;

Expand Down
1 change: 1 addition & 0 deletions src/EnumPro.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Lazerg\LaravelEnumPro;

Expand Down
7 changes: 2 additions & 5 deletions src/EnumRandom.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Lazerg\LaravelEnumPro;

Expand All @@ -15,11 +16,7 @@ trait EnumRandom
*/
public static function random(int $count = 1): Collection
{
if ($count > self::values()->count()) {
throw new InvalidArgumentException('Count of random values is greater than count of enum values');
}

return self::values()->shuffle()->take($count);
return self::values()->random($count);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/EnumStaticCalls.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Lazerg\LaravelEnumPro;

Expand Down
9 changes: 2 additions & 7 deletions src/EnumValues.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Lazerg\LaravelEnumPro;

Expand Down Expand Up @@ -48,12 +49,6 @@ public static function valueOf(string $name): null|int|string
{
$name = Str::replace(' ', '_', Str::upper($name));

foreach (self::cases() as $case) {
if ($case->name === $name) {
return $case->value;
}
}

return null;
return array_column(self::cases(), 'value', 'name')[$name] ?? null;
}
}
1 change: 1 addition & 0 deletions tests/EnumNamesTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

test('Get name of enums as collection', function () {
expect(LevelTypes::names())
Expand Down
1 change: 1 addition & 0 deletions tests/EnumOptionsTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

test('Get options of enum as collection', function () {
expect(LevelTypes::options())
Expand Down
1 change: 1 addition & 0 deletions tests/EnumTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

/**
* @noinspection PhpIllegalPsrClassPathInspection
Expand Down
1 change: 1 addition & 0 deletions tests/EnumValuesTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

test('Get values of enum as collection', function () {
expect(LevelTypes::values())
Expand Down
Loading