Completed
Push — master ( 699dc6...d8f60e )
by Changwan
05:50
created

StringCaster::cast()   B

Complexity

Conditions 8
Paths 5

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 8

Importance

Changes 0
Metric Value
cc 8
eloc 8
nc 5
nop 1
dl 0
loc 12
ccs 8
cts 8
cp 1
crap 8
rs 7.7777
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Caster\Caster;
3
4
use Wandu\Caster\CasterInterface;
5
6
class StringCaster implements CasterInterface 
7
{
8
    /**
9
     * {@inheritdoc}
10
     */
11 14
    public function cast($value)
12
    {
13 14
        if ($value === null || (is_array($value) && count($value) === 0)) {
14 1
            return '';
15
        }
16 13
        if ($value === true) return 'true';
17 12
        if ($value === false) return 'false';
18 11
        if (is_array($value) || is_object($value)) {
19 1
            return json_encode($value);
20
        }
21 10
        return (string) $value;
22
    }
23
}
24