ExtractIdMutation   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 18
rs 10
c 1
b 0
f 0
wmc 6

1 Method

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