Completed
Push — master ( f7ebb3...191d10 )
by Alex
23s queued 11s
created

checkRelationPropertiesCached()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 15
rs 9.9
cc 4
nc 4
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: alex
5
 * Date: 15/02/20
6
 * Time: 6:43 PM
7
 */
8
9
namespace AlgoWeb\PODataLaravel\Serialisers;
10
11
use POData\Providers\Metadata\ResourceEntityType;
12
13
trait SerialisePropertyCacheTrait
14
{
15
    protected $propertiesCache = [];
16
17
    /**
18
     * @param string $targClass
19
     * @param ResourceEntityType $resourceType
20
     * @return void
21
     * @throws \ReflectionException
22
     */
23
    protected function checkRelationPropertiesCached($targClass, ResourceEntityType $resourceType)
24
    {
25
        if (!array_key_exists($targClass, $this->propertiesCache)) {
26
            $rawProp = $resourceType->getAllProperties();
27
            $relProp = [];
28
            $nonRelProp = [];
29
            foreach ($rawProp as $prop) {
30
                $propType = $prop->getResourceType();
31
                if ($propType instanceof ResourceEntityType) {
32
                    $relProp[] = $prop;
33
                } else {
34
                    $nonRelProp[$prop->getName()] = ['prop' => $prop, 'type' => $propType->getInstanceType()];
35
                }
36
            }
37
            $this->propertiesCache[$targClass] = ['rel' => $relProp, 'nonRel' => $nonRelProp];
38
        }
39
    }
40
}
41