Jsonable   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 20
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 15 6
1
<?php
2
3
namespace Glorand\Drip\Models\Traits;
4
5
trait Jsonable
6
{
7 6
    public function jsonSerialize(): array
8
    {
9 6
        $response = [];
10 6
        $attributes = get_object_vars($this);
11 6
        foreach ($attributes as $attribute => $value) {
12 6
            if (is_array($value) && count($value)) {
13 3
                $response[$attribute] = $value;
14 6
            } elseif ($value instanceof \DateTime) {
15 2
                $response[$attribute] = $value->format(DATE_ISO8601);
16 6
            } elseif (!empty($value)) {
17 6
                $response[$attribute] = $value;
18
            }
19
        }
20
21 6
        return $response;
22
    }
23
24
    abstract public function toDrip(): array;
25
}
26