Completed
Push — master ( 0972fb...ca0d04 )
by Ben
02:22
created

Base::asBoolean()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 3
eloc 4
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Benrowe\Formatter\Providers;
4
5
use Benrowe\Formatter\AbstractFormatterProvider;
6
7
/**
8
 * @package Benrowe\Formatter
9
 */
10
class Base extends AbstractFormatterProvider
11
{
12
    public $booleanFormat = ['No', 'Yes'];
13
14
    /**
15
     * Handle the raw content
16
     *
17
     * @param  mixed $value
18
     * @return mixed
19
     */
20 4
    public function asRaw($value)
21
    {
22 4
        if ($value === null) {
23 1
            return $this->nullValue;
24
        }
25 3
        return $value;
26
    }
27
28
    /**
29
     * As text
30
     *
31
     * @param  mixed $value
32
     * @return string
33
     */
34 3
    public function asText($value)
35
    {
36 3
        if ($value === null) {
37 1
            return $this->nullValue;
38
        }
39
40 2
        return htmlentities($value);
41
    }
42
43
    /**
44
     * Format the value using the boolean values
45
     *
46
     * @param  mixed $value
47
     * @return string
48
     */
49 8
    public function asBoolean($value)
50
    {
51 8
        if ($value === null) {
52 1
            return $this->nullValue;
53
        }
54 7
        return $value ? $this->booleanFormat[1] : $this->booleanFormat[0];
55
    }
56
}
57