Skip to content

Commit 54bedef

Browse files
authored
use array_column() to get the names, values, and options (#3)
1 parent c733871 commit 54bedef

File tree

3 files changed

+3
-11
lines changed

3 files changed

+3
-11
lines changed

src/Names.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ trait Names
99
/** Get an array of case names. */
1010
public static function names(): array
1111
{
12-
return array_map(function ($case) {
13-
return $case->name;
14-
}, static::cases());
12+
return array_column(static::cases(), 'name');
1513
}
1614
}

src/Options.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ trait Options
99
/** Get an associative array of [case name => case value]. */
1010
public static function options(): array
1111
{
12-
return array_reduce(static::cases(), function ($options, $case) {
13-
$options[$case->name] = $case->value;
14-
15-
return $options;
16-
}, []);
12+
return array_column(static::cases(), 'value', 'name');
1713
}
1814
}

src/Values.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ trait Values
99
/** Get an array of case values. */
1010
public static function values(): array
1111
{
12-
return array_map(function ($case) {
13-
return $case->value;
14-
}, static::cases());
12+
return array_column(static::cases(), 'value');
1513
}
1614
}

0 commit comments

Comments
 (0)