Passed
Pull Request — master (#204)
by Alex
05:48
created

SerialisePropertyCacheTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A checkRelationPropertiesCached() 0 15 4
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