ToArrayTrait::toArray()   A
last analyzed

Complexity

Conditions 4
Paths 1

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 20
rs 9.9332
1
<?php
2
3
namespace Aura\Marshal;
4
5
use Aura\Marshal\Lazy\GenericLazy;
6
7
trait ToArrayTrait
8
{
9
    public function toArray(): array
10
    {
11
        return array_map(
12
            function ($entity)
13
            {
14
                if ($entity instanceof GenericLazy) {
15
                    $entity = $entity->get($this);
16
                }
17
18
                if ($entity instanceof ToArrayInterface) {
19
                    return $entity->toArray();
20
                }
21
22
                if (is_object($entity)) {
23
                    return (array) $entity;
24
                }
25
26
                return $entity;
27
            },
28
            $this->data
29
        );
30
    }
31
}
32