Completed
Push — master ( 7cb054...584ba8 )
by Tim
44:11 queued 26:38
created

Booleans   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 22
rs 10
wmc 4
lcom 0
cbo 1
1
<?php
2
/*
3
 * Copyright (c) Ouzo contributors, http://ouzoframework.org
4
 * This file is made available under the MIT License (view the LICENSE file for more information).
5
 */
6
namespace Ouzo\Utilities;
7
8
/**
9
 * Class Booleans
10
 * @package Ouzo\Utilities
11
 */
12
class Booleans
13
{
14
    /**
15
     * @param $string
16
     * @return bool
17
     */
18
    public static function toBoolean($string)
19
    {
20
        if (is_bool($string)) {
21
            return $string;
22
        }
23
        $string = strtolower($string);
24
        $specials = array('true', 'on', 'yes');
25
        if (in_array($string, $specials)) {
26
            return true;
27
        }
28
        if (Strings::equal($string, 'false')) {
29
            return false;
30
        }
31
        return !is_string($string);
32
    }
33
}
34