Completed
Push — feature/EVO-4597-rabbitmq-hand... ( 6e503b...616297 )
by
unknown
52:22 queued 46:35
created

FieldJsonMapper::map()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4.0466
Metric Value
dl 0
loc 18
ccs 12
cts 14
cp 0.8571
rs 9.2
cc 4
eloc 9
nc 3
nop 2
crap 4.0466
1
<?php
2
/**
3
 * add singular names to fields
4
 */
5
6
namespace Graviton\GeneratorBundle\Generator\ResourceGenerator;
7
8
use Graviton\GeneratorBundle\Definition\JsonDefinition;
9
use Graviton\GeneratorBundle\Definition\DefinitionElementInterface;
10
11
/**
12
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
13
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
14
 * @link     http://swisscom.ch
15
 */
16
class FieldJsonMapper implements FieldMapperInterface
17
{
18
    /**
19
     * @param array $field   mappable field with type attribute
20
     * @param mixed $context context for mapper to check
21
     *
22
     * @return array
23
     */
24 2
    public function map($field, $context = null)
25
    {
26 2
        if ($context instanceof JsonDefinition &&
27 2
            $context->getField($field['fieldName']) instanceof DefinitionElementInterface
28 2
        ) {
29 2
            $fieldInformation = $context->getField($field['fieldName'])
30 2
                ->getDefAsArray();
31
32
            // in this context, the default type is the doctrine type..
33 2
            if (isset($fieldInformation['doctrineType'])) {
34 1
                $fieldInformation['type'] = $fieldInformation['doctrineType'];
35 1
            }
36
37 2
            $field = array_merge($field, $fieldInformation);
38 2
        }
39
40 2
        return $field;
41
    }
42
}
43