Passed
Pull Request — master (#14)
by Pavel
05:12
created

IdentifierFixer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
dl 0
loc 25
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2
ccs 7
cts 8
cp 0.875
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fixScalarId() 0 15 3
1
<?php
2
3
namespace Bankiru\Api\Doctrine\Utility;
4
5
use Bankiru\Api\Doctrine\Exception\MappingException;
6
use Bankiru\Api\Doctrine\Mapping\ApiMetadata;
7
8
final class IdentifierFixer
9
{
10
    /**
11
     * @param array|mixed $id
12
     * @param ApiMetadata $metadata
13
     *
14
     * @return array
15
     * @throws MappingException
16
     */
17 12
    public static function fixScalarId($id, ApiMetadata $metadata)
18
    {
19 12
        if (is_array($id)) {
20 6
            return $id;
21
        }
22
23 11
        $id = (array)$id;
24
25 11
        $identifiers = $metadata->getIdentifierFieldNames();
26 11
        if (count($id) !== count($identifiers)) {
27
            throw MappingException::invalidIdentifierStructure();
28
        }
29
30 11
        return array_combine($identifiers, (array)$id);
31
    }
32
}
33