Completed
Push — master ( abe21f...dd633f )
by Ben
02:41
created

Boolean::canHandleFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Benrowe\Laravel\Config\Modifiers;
4
5
/**
6
 * Boolean modifier for Config
7
 *
8
 * @package Benrowe\Laravel\Config\Modifiers
9
 */
10
class Boolean implements Modifier
11
{
12
    /**
13
     * Determine if this value is boolean
14
     *
15
     * @param  string $value
16
     * @return boolean
17
     */
18
    public function canHandleFrom($value)
19
    {
20
        return is_bool($value);
21
    }
22
23
    /**
24
     * Determine if we can convert this string into a boolean
25
     * @param  string $value
26
     * @return boolean
27
     */
28
    public function canHandleTo($value)
29
    {
30
        return $value === 'true' || $value === 'false';
31
    }
32
33
    /**
34
     * Convert the string into the boolean
35
     *
36
     * @param  string|array $value
37
     * @return boolean
38
     */
39
    public function convertTo($value)
40
    {
41
        return $value === 'true';
42
    }
43
44
    /**
45
     * Convert the complex object back to a string
46
     *
47
     * @param  bool $value
48
     * @return string
49
     */
50
    public function convertFrom($value)
51
    {
52
        return $value === true ? 'true' : 'false';
53
    }
54
}
55