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

FieldJsonMapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 85.71%
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 27
ccs 12
cts 14
cp 0.8571
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A map() 0 18 4
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