-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if value is
int
or string
in conversion of `Enum::hasValue(…
…)` to native enum
- Loading branch information
Showing
5 changed files
with
174 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,49 @@ | ||
<?php | ||
|
||
use BenSampo\Enum\Tests\Enums\UserType; | ||
use BenSampo\Enum\Tests\Enums\StringValues; | ||
|
||
UserType::hasValue('foo'); | ||
UserType::hasValue('foo', false); | ||
/** @var int $int */ | ||
/** @var string $string */ | ||
/** @var bool $bool */ | ||
/** @var mixed $mixed */ | ||
|
||
UserType::hasValue($int); | ||
UserType::hasValue($string); | ||
UserType::hasValue($bool); | ||
UserType::hasValue($mixed); | ||
UserType::hasValue(UserType::Administrator); | ||
|
||
StringValues::hasValue($int); | ||
StringValues::hasValue($string); | ||
StringValues::hasValue($bool); | ||
StringValues::hasValue($mixed); | ||
StringValues::hasValue(StringValues::Administrator); | ||
|
||
UserType::hasValue(...); | ||
StringValues::hasValue(...); | ||
----- | ||
<?php | ||
|
||
use BenSampo\Enum\Tests\Enums\UserType; | ||
use BenSampo\Enum\Tests\Enums\StringValues; | ||
|
||
/** @var int $int */ | ||
/** @var string $string */ | ||
/** @var bool $bool */ | ||
/** @var mixed $mixed */ | ||
|
||
UserType::tryFrom('foo') !== null; | ||
UserType::tryFrom('foo') !== null; | ||
UserType::tryFrom($int) !== null; | ||
false; | ||
false; | ||
is_int($mixed) && UserType::tryFrom($mixed) !== null; | ||
true; | ||
static fn(mixed $value): bool => UserType::tryFrom($value) !== null; | ||
|
||
false; | ||
StringValues::tryFrom($string) !== null; | ||
false; | ||
is_string($mixed) && StringValues::tryFrom($mixed) !== null; | ||
true; | ||
|
||
static fn(mixed $value): bool => is_int($value) && UserType::tryFrom($value) !== null; | ||
static fn(mixed $value): bool => is_string($value) && StringValues::tryFrom($value) !== null; |