Completed
Push — feature/serialiser-update-1.4.... ( 7d57c7 )
by
unknown
23:35
created

ArrayField   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 46.67%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 45
rs 10
c 0
b 0
f 0
ccs 7
cts 15
cp 0.4667

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getItemType() 0 16 3
1
<?php
2
/**
3
 * ArrayField class file
4
 */
5
6
namespace Graviton\DocumentBundle\DependencyInjection\Compiler\Utils;
7
8
/**
9
 * Document array field
10
 *
11
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
12
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
13
 * @link     http://swisscom.ch
14
 */
15
class ArrayField extends AbstractField
16
{
17
    /**
18
     * @var string
19
     */
20
    private $serializerType;
21
22
    /**
23
     * Constructor
24
     *
25
     * @param string $serializerType        Field type
26
     * @param string $fieldName             Field name
27
     * @param string $exposedName           Exposed name
28
     * @param bool   $readOnly              Read only
29
     * @param bool   $required              Is required
30
     * @param bool   $recordOriginException Is an exception to record origin
31
     */
32 2
    public function __construct($serializerType, $fieldName, $exposedName, $readOnly, $required, $recordOriginException)
33
    {
34 2
        $this->serializerType = $serializerType;
35 2
        parent::__construct($fieldName, $exposedName, $readOnly, $required, false, $recordOriginException);
36 2
    }
37
38
    /**
39
     * Get item type
40
     *
41
     * @return string
42
     */
43 2
    public function getItemType()
44
    {
45 2
        if (!preg_match('/array\<(.+)\>/i', $this->serializerType, $matches)) {
46 2
            return $this->serializerType;
47
        }
48
49
        $map = [
50
            'DateTime'  => 'date',
51
            'integer'   => 'int',
52
            'float'     => 'float',
53
            'double'    => 'float',
54
            'boolean'   => 'boolean',
55
            'extref'    => 'extref',
56
        ];
57
        return isset($map[$matches[1]]) ? $map[$matches[1]] : $matches[1];
58
    }
59
}
60