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

ArrayCaster   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A cast() 0 14 4
1
<?php
2
namespace Wandu\Caster\Caster;
3
4
use Wandu\Caster\CasterInterface;
5
6
class ArrayCaster implements CasterInterface
7
{
8
    /**
9
     * {@inheritdoc}
10
     */
11 23
    public function cast($value)
12
    {
13 23
        if (is_string($value)) {
14 13
            $result = json_decode($value, true);
15 13
            if (json_last_error() === \JSON_ERROR_NONE) {
16 10
                return (array) $result;
17
            }
18 3
            $result = json_decode("[{$value}]", true);
19 3
            if (json_last_error() === \JSON_ERROR_NONE) {
20 3
                return (array) $result;
21
            }
22
        }
23 10
        return (array) $value;
24
    }
25
}
26