Passed
Push — master ( b5b8d0...1c0f33 )
by Tom
03:11
created

PageData::parseArray()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 29
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 7

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 29
ccs 15
cts 15
cp 1
rs 8.8333
c 0
b 0
f 0
cc 7
nc 8
nop 1
crap 7
1
<?php
2
3
namespace Astrotomic\Stancy\Models;
4
5
use DateTime;
6
use Illuminate\Contracts\Support\Arrayable;
7
use Spatie\DataTransferObject\DataTransferObject;
8
9
abstract class PageData extends DataTransferObject implements Arrayable
10
{
11 9
    public static function make(array $data): self
0 ignored issues
show
introduced by
Method \Astrotomic\Stancy\Models\PageData::make() does not have @param annotation for its traversable parameter $data.
Loading history...
12
    {
13 9
        return new static($data);
14
    }
15
16
    // https://github.com/spatie/data-transfer-object/issues/64
17 5
    protected function parseArray(array $array): array
0 ignored issues
show
introduced by
Only 2 indentation levels per function/method. Found 3 levels.
Loading history...
introduced by
Method \Astrotomic\Stancy\Models\PageData::parseArray() does not have @param annotation for its traversable parameter $array.
Loading history...
introduced by
Method \Astrotomic\Stancy\Models\PageData::parseArray() does not have @return annotation for its traversable return value.
Loading history...
18
    {
19 5
        foreach ($array as $key => $value) {
20 5
            if (is_object($value)) {
21 5
                if($value instanceof DateTime) {
0 ignored issues
show
introduced by
You should change the following
<fg=red>- if($value instanceof DateTime) {
</><fg=green>+ if ($value instanceof DateTime) {
</>
Loading history...
22 1
                    $array[$key] = $value->format(DATE_RFC3339);
23
24 1
                    continue;
25
                }
26
27 5
                if (method_exists($value, 'toArray')) {
28 1
                    $array[$key] = $value->toArray();
29
30 1
                    continue;
31
                }
32
33 5
                if (method_exists($value, '__toString')) {
34 5
                    $array[$key] = $value->__toString();
35
36 5
                    continue;
37
                }
38
            }
39
40 5
            if (is_array($value)) {
41 5
                $array[$key] = $this->parseArray($value);
42
            }
43
        }
44
45 5
        return $array;
46
    }
47
}
48