checkRelationPropertiesCached()   A
last analyzed

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
declare(strict_types=1);
4
/**
5
 * Created by PhpStorm.
6
 * User: alex
7
 * Date: 15/02/20
8
 * Time: 6:43 PM.
9
 */
10
namespace AlgoWeb\PODataLaravel\Serialisers;
11
12
use POData\Providers\Metadata\ResourceEntityType;
13
14
trait SerialisePropertyCacheTrait
15
{
16
    /** @var array[] */
17
    protected $propertiesCache = [];
18
19
    /**
20
     * @param  string               $targClass
21
     * @param  ResourceEntityType   $resourceType
22
     * @throws \ReflectionException
23
     * @return void
24
     */
25
    protected function checkRelationPropertiesCached(string $targClass, ResourceEntityType $resourceType)
26
    {
27
        if (!array_key_exists($targClass, $this->propertiesCache)) {
28
            $rawProp    = $resourceType->getAllProperties();
29
            $relProp    = [];
30
            $nonRelProp = [];
31
            foreach ($rawProp as $prop) {
32
                $propType = $prop->getResourceType();
33
                if ($propType instanceof ResourceEntityType) {
34
                    $relProp[] = $prop;
35
                } else {
36
                    $nonRelProp[$prop->getName()] = ['prop' => $prop, 'type' => $propType->getInstanceType()];
37
                }
38
            }
39
            $this->propertiesCache[$targClass] = ['rel' => $relProp, 'nonRel' => $nonRelProp];
40
        }
41
    }
42
}
43