AbstractHydratorStrategy   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A resolveId() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\LaminasDoctrine\Hydrator\Strategy;
6
7
use Arp\Entity\EntityInterface;
8
use Arp\LaminasDoctrine\Repository\EntityRepositoryInterface;
9
use Laminas\Hydrator\Strategy\StrategyInterface;
10
11
abstract class AbstractHydratorStrategy implements StrategyInterface
12
{
13
    /**
14
     * @var EntityRepositoryInterface<EntityInterface>
15
     */
16
    protected EntityRepositoryInterface $repository;
17
18
    /**
19
     * @param EntityRepositoryInterface<EntityInterface> $repository
20
     */
21
    public function __construct(EntityRepositoryInterface $repository)
22
    {
23
        $this->repository = $repository;
24
    }
25
26
    /**
27
     * @param mixed $value
28
     *
29
     * @return mixed
30
     */
31
    protected function resolveId($value)
32
    {
33
        if (is_array($value)) {
34
            $id = $value['id'] ?? null;
35
            unset($value['id']);
36
        } elseif ($value instanceof EntityInterface) {
37
            $id = $value->getId();
38
        } else {
39
            $id = $value;
40
        }
41
42
        return $id;
43
    }
44
}
45