From 5f2b92e9bffbd558fc7dcf84c3121a1b782a05b8 Mon Sep 17 00:00:00 2001 From: Yuvi Date: Wed, 29 Jun 2016 15:55:00 +0200 Subject: [PATCH] null if invalid boolean --- src/BooleanParser.php | 8 +++++++- src/YesNoBooleanParser.php | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/BooleanParser.php b/src/BooleanParser.php index e333a07..16f4b4e 100644 --- a/src/BooleanParser.php +++ b/src/BooleanParser.php @@ -6,7 +6,13 @@ class BooleanParser extends AbstractValueParser { protected function parse($value) { - return strtoupper($value) === 'TRUE' || strtoupper($value) === '1'; + if (strtoupper($value) === 'TRUE' || $value === '1') { + return true; + } + if (strtoupper($value) === 'FALSE' || $value === '0') { + return false; + } + return null; } /** diff --git a/src/YesNoBooleanParser.php b/src/YesNoBooleanParser.php index f19993b..486607c 100644 --- a/src/YesNoBooleanParser.php +++ b/src/YesNoBooleanParser.php @@ -6,7 +6,13 @@ class YesNoBooleanParser extends AbstractValueParser { protected function parse($value) { - return strtoupper($value) === 'YES' || strtoupper($value) === 'Y'; + if (strtoupper($value) === 'YES' || strtoupper($value) === 'Y') { + return true; + } + if (strtoupper($value) === 'NO' || strtoupper($value) === 'N') { + return false; + } + return null; } /**