From 32b494ea1b59f5c8a37de914e755dc6bf9a6ee20 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Thu, 11 Jan 2018 18:21:02 +0800 Subject: [PATCH] Boolean formatter --- src/Formatters/BooleanFormatter.php | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/Formatters/BooleanFormatter.php diff --git a/src/Formatters/BooleanFormatter.php b/src/Formatters/BooleanFormatter.php new file mode 100644 index 0000000..f6cd328 --- /dev/null +++ b/src/Formatters/BooleanFormatter.php @@ -0,0 +1,33 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Formatters; + +use InvalidArgumentException; +use Web3\Utils; +use Web3\Formatters\IFormatter; + +class BooleanFormatter implements IFormatter +{ + /** + * format + * + * @param mixed $value + * @return int + */ + public static function format($value) + { + if (!is_bool($value)) { + throw new InvalidArgumentException('The value to inputFormat function must be boolean.'); + } + return (int) $value; + } +} \ No newline at end of file