Skip to content

Commit

Permalink
bug #53 Fix Autodiscovered values must only be int or string (ogizanagi)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.x-dev branch.

Discussion
----------

Fix Autodiscovered values must only be int or string

Fixes #52

Commits
-------

fa357c0 Fix Autodiscovered values must only be int or string
  • Loading branch information
ogizanagi committed Apr 16, 2018
2 parents c575970 + fa357c0 commit 5c487f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/AutoDiscoveredValuesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ private static function autodiscoveredValues(): array
$values = array_filter($values, function ($v) {
return is_int($v) && 0 === ($v & $v - 1) && $v > 0;
});
} else {
$values = array_filter($values, function ($v) {
return is_int($v) || is_string($v);
});
}

self::$guessedValues[$enumType] = array_values($values);
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/AutoDiscoveredValuesTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ final class AutoDiscoveredEnum extends Enum
const FOO = 'foo';
const BAR = 'bar';
const BAZ = 'baz';

const NOT_AN_INT_NOR_STRING = ['foo'];
}

final class AutoDiscoveredFlaggedEnum extends FlaggedEnum
Expand Down

0 comments on commit 5c487f4

Please sign in to comment.