Base::asRaw()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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