ExtractIdMutation::__invoke()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 7
nc 5
nop 2
dl 0
loc 15
rs 9.2222
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Blackmine\Mutator\Mutation;
6
7
class ExtractIdMutation extends AbstractMutation
8
{
9
10
    public function __invoke(array $target, array ...$args): array
11
    {
12
        [$key] = $args[0];
13
14
        if (isset($target[$key]) && is_array($target[$key])) {
15
            if (isset($target[$key]["id"])) {
16
                $target[$key] = $target[$key]["id"];
17
            }
18
19
            if (is_object($target[$key]) && method_exists($target[$key], "getId")) {
20
                $target[$key] = $target[$key]->getId();
21
            }
22
        }
23
24
        return $target;
25
    }
26
}
27