| @@ 26-44 (lines=19) @@ | ||
| 23 | /** |
|
| 24 | * @package Limoncello\Validation |
|
| 25 | */ |
|
| 26 | final class StringToFloat extends ExecuteRule |
|
| 27 | { |
|
| 28 | /** |
|
| 29 | * @param mixed $value |
|
| 30 | * @param ContextInterface $context |
|
| 31 | * |
|
| 32 | * @return array |
|
| 33 | * |
|
| 34 | * @SuppressWarnings(PHPMD.StaticAccess) |
|
| 35 | */ |
|
| 36 | public static function execute($value, ContextInterface $context): array |
|
| 37 | { |
|
| 38 | if (is_string($value) === true || is_numeric($value) === true) { |
|
| 39 | return static::createSuccessReply((float)$value); |
|
| 40 | } |
|
| 41 | ||
| 42 | return static::createErrorReply($context, $value, ErrorCodes::IS_FLOAT); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||
| @@ 26-44 (lines=19) @@ | ||
| 23 | /** |
|
| 24 | * @package Limoncello\Validation |
|
| 25 | */ |
|
| 26 | final class StringToInt extends ExecuteRule |
|
| 27 | { |
|
| 28 | /** |
|
| 29 | * @param mixed $value |
|
| 30 | * @param ContextInterface $context |
|
| 31 | * |
|
| 32 | * @return array |
|
| 33 | * |
|
| 34 | * @SuppressWarnings(PHPMD.StaticAccess) |
|
| 35 | */ |
|
| 36 | public static function execute($value, ContextInterface $context): array |
|
| 37 | { |
|
| 38 | if (is_string($value) === true || is_numeric($value) === true) { |
|
| 39 | return static::createSuccessReply((int)$value); |
|
| 40 | } |
|
| 41 | ||
| 42 | return static::createErrorReply($context, $value, ErrorCodes::IS_INT); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||