Ouzo\Utilities\Booleans::toBoolean PHP Méthode

toBoolean() public static méthode

public static toBoolean ( $string ) : boolean
$string
Résultat boolean
    public static function toBoolean($string)
    {
        if (is_numeric($string)) {
            return $string != 0;
        }
        return filter_var($string, FILTER_VALIDATE_BOOLEAN);
    }

Usage Example

Exemple #1
0
 /**
  * @test
  * @dataProvider toBoolean
  * @param $string
  * @param $expected
  */
 public function shouldConvertToBoolean($string, $expected)
 {
     //when
     $toBoolean = Booleans::toBoolean($string);
     //then
     $this->assertEquals($expected, $toBoolean, 'To convert: ' . Objects::toString($string) . ' Expected: ' . Objects::toString($expected));
 }
Booleans