Completed
Push — master ( 5f432b...5d5b15 )
by Jens
15:50 queued 05:48
created

FieldContainer::fieldDefinition()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 7.457

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 28
ccs 15
cts 19
cp 0.7895
rs 6.7272
cc 7
eloc 19
nc 7
nop 1
crap 7.457
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#customfields
18
 */
19
class FieldContainer extends JsonObject
20
{
21 15
    public function fieldDefinition($field)
22
    {
23 15
        if (!$this->parent instanceof CustomFieldObject) {
24 1
            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 1
    public function set($field, $value)
56
    {
57 1
        return parent::set($field, $value);
58
    }
59
60 14
    protected function isValidField($field)
61
    {
62 14
        return true;
63
    }
64
}
65