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

StringCaster   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B cast() 0 12 8
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