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