Completed
Push — master ( fa9a11...9c37c7 )
by Jens
13:15
created

FieldContainer   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 76.19%
Metric Value
wmc 9
lcom 1
cbo 7
dl 0
loc 46
ccs 16
cts 21
cp 0.7619
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasField() 0 4 1
C fieldDefinition() 0 28 7
A set() 0 4 1
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\CustomField;
7
8
use Commercetools\Core\Model\Common\JsonObject;
9
use Commercetools\Core\Model\Type\FieldDefinition;
10
use Commercetools\Core\Model\Type\FieldDefinitionCollection;
11
use Commercetools\Core\Model\Type\FieldType;
12
use Commercetools\Core\Model\Type\Type;
13
use Commercetools\Core\Model\Type\TypeReference;
14
15
/**
16
 * @package Commercetools\Core\Model\CustomField
17
 * @link https://dev.commercetools.com/http-api-projects-custom-fields.html#custom-fields
18
 */
19
class FieldContainer extends JsonObject
20
{
21 14
    public function fieldDefinition($field)
22
    {
23 14
        if (!$this->parent instanceof CustomFieldObject) {
24
            return null;
25
        }
26 14
        $typeReference = $this->parent->getType();
27
28 14
        if (!$typeReference instanceof TypeReference) {
29
            return null;
30
        }
31 14
        $type = $typeReference->getObj();
32 14
        if (!$type instanceof Type) {
33 7
            return null;
34
        }
35 7
        $fieldDefinitions = $type->getFieldDefinitions();
36 7
        if (!$fieldDefinitions instanceof FieldDefinitionCollection) {
37
            return null;
38
        }
39 7
        $fieldDefinition = $fieldDefinitions->getByName($field);
40 7
        if (!$fieldDefinition instanceof FieldDefinition) {
41
            return null;
42
        }
43 7
        $fieldType = $fieldDefinition->getType();
44 7
        if (!$fieldType instanceof FieldType) {
45
            return null;
46
        }
47 7
        return $fieldType->fieldTypeDefinition();
48
    }
49
50
    /**
51
     * @param string $field
52
     * @param mixed $value
53
     * @return $this
54
     */
55
    public function set($field, $value)
56
    {
57
        return parent::set($field, $value);
58
    }
59
60 14
    public function hasField($field)
61
    {
62 14
        return true;
63
    }
64
}
65