Completed
Push — master ( 12f48c...b47ac0 )
by Gaetano
06:59
created

ComplexFieldManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 5
Bugs 0 Features 2
Metric Value
c 5
b 0
f 2
dl 0
loc 42
rs 10
wmc 4
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addComplexField() 0 4 1
A getComplexFieldValue() 0 15 2
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core\ComplexField;
4
5
use Kaliop\eZMigrationBundle\API\ComplexFieldInterface;
6
use eZ\Publish\API\Repository\FieldTypeService;
7
8
class ComplexFieldManager
9
{
10
    /** @var ComplexFieldInterface[]  */
11
    protected $fieldTypeMap;
12
    protected $fieldTypeService;
13
14
    public function __construct(FieldTypeService $fieldTypeService)
15
    {
16
        $this->fieldTypeService = $fieldTypeService;
17
    }
18
19
    /**
20
     * @param ComplexFieldInterface $complexField
21
     * @param string $contentTypeIdentifier
22
     */
23
    public function addComplexField(ComplexFieldInterface $complexField, $contentTypeIdentifier)
24
    {
25
        $this->fieldTypeMap[$contentTypeIdentifier] = $complexField;
26
    }
27
28
    /**
29
     * @param string $fieldTypeIdentifier
30
     * @param array $fieldValueArray
31
     * @param array $context
32
     * @return ComplexFieldInterface
33
     */
34
    public function getComplexFieldValue($fieldTypeIdentifier, array $fieldValueArray, array $context = array())
35
    {
36
        if (array_key_exists($fieldTypeIdentifier, $this->fieldTypeMap))
37
        {
38
            $fieldService = $this->fieldTypeMap[$fieldTypeIdentifier];
39
            return $fieldService->createValue($fieldValueArray, $context);
40
        }
41
        else
42
        {
43
            $fieldType = $this->fieldTypeService->getFieldType($fieldTypeIdentifier);
44
            return $fieldType->fromHash($fieldValueArray);
45
            // was: error
46
            //throw new \InvalidArgumentException("Field of type '$fieldTypeIdentifier' can not be handled as it does not have a complex field class defined");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47
        }
48
    }
49
}
50