granam / float-enum
Enumeration with floats only
1.1.0
2021-03-23 17:48 UTC
Requires
- php: >=7.3
- granam/float: ^5.0
- granam/scalar-enum: ^1.1
Requires (Dev)
- granam/exceptions-hierarchy: ^5.0
- mockery/mockery: ^1.2
- phpunit/phpunit: ^9.0
README
Usage
Use enum
<?php use \Granam\FloatEnum\FloatEnum; $enum = FloatEnum::getEnum(123); echo $enum->getValue(); // 123 var_dump($enum->getValue()); // (float) 123.0 var_dump($enum->is(123.0)); // true var_dump($enum->is(123)); // false var_dump($enum->is('123.0')); // false var_dump($enum->is($enum)); // true
NULL is NULL, enum can not hold it
You can not create FloatEnum with NULL value. Just use NULL directly for such value.
<?php try { \Granam\FloatEnum\FloatEnum::getEnum(null); } catch(\Granam\FloatEnum\Exceptions\WrongValueForFloatEnum $wrongValueForFloatEnum) { echo $wrongValueForFloatEnum->getMessage(); // Expected float or object with __toString method on strict mode, got NULL }
Installation
composer.phar require granam/float-enum
or manually edit composer.json at your project and "require":
block (extend existing)
"require": { "granam/float-enum": "dev-master" }