Completed
Push — master ( c48e82...f5ca2c )
by Luc
15s queued 13s
created

RegistrationJsonEnricher::enrich()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Account\Serializers;
4
5
use Ramsey\Uuid\UuidFactoryInterface;
6
use VSV\GVQ_API\Common\Serializers\JsonEnricher;
7
use VSV\GVQ_API\User\ValueObjects\Role;
8
9
class RegistrationJsonEnricher implements JsonEnricher
10
{
11
    /**
12
     * @var UuidFactoryInterface
13
     */
14
    private $uuidFactory;
15
16
    /**
17
     * @param UuidFactoryInterface $uuidFactory
18
     */
19
    public function __construct(UuidFactoryInterface $uuidFactory)
20
    {
21
        $this->uuidFactory = $uuidFactory;
22
    }
23
24
    /**
25
     * @param string $json
26
     * @return string
27
     */
28
    public function enrich(string $json): string
29
    {
30
        $registrationAsArray = json_decode($json, true);
31
32
        $registrationAsArray['id'] = $this->uuidFactory->uuid4()->toString();
33
34
        for ($index = 0; $index < count($registrationAsArray['aliases']); $index++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
35
            $registrationAsArray['aliases'][$index]['id'] = $this->uuidFactory->uuid4()->toString();
36
        }
37
38
        $registrationAsArray['user']['id'] = $this->uuidFactory->uuid4()->toString();
39
        $registrationAsArray['user']['role'] = Role::CONTACT;
40
41
        return json_encode($registrationAsArray);
42
    }
43
}
44