for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Mbright\Validation\Rule;
class AbstractBooleanCase
{
/**
* Pseudo-true representations.
*
* @var array
*/
protected $true = array('1', 'on', 'true', 't', 'yes', 'y');
* Pseudo-false representations; `null` and empty-string are *not* included.
protected $false = array('0', 'off', 'false', 'f', 'no', 'n');
* Is a value true-ish?
* @param mixed $value The value to check.
* @return bool
protected function isTrue($value)
if (!$this->isBoolIsh($value)) {
return false;
}
return $value === true || in_array(strtolower(trim($value)), $this->true);
* Is a value false-ish?
protected function isFalse($value)
return $value === false || in_array(strtolower(trim($value)), $this->false);
* Can the value be checked for true/false-ish-ness?
protected function isBoolIsh($value)
if (is_string($value) || is_int($value) || is_bool($value)) {
return true;