Passed
Push — master ( 78880b...ac7e2f )
by Jens
20:00 queued 13s
created

CustomFieldObjectDraft   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 82.35%

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 62
ccs 14
cts 17
cp 0.8235
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A ofTypeKey() 0 5 1
A ofTypeKeyAndFields() 0 5 1
A ofType() 0 5 1
A ofTypeId() 0 5 1
A ofTypeAndFields() 0 5 1
1
<?php
2
/**
3
 * @author @jenschude <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\CustomField;
7
8
use Commercetools\Core\Model\Common\Context;
9
use Commercetools\Core\Model\Common\JsonObject;
10
use Commercetools\Core\Model\Type\TypeReference;
11
use Commercetools\Core\Model\Common\ResourceIdentifier;
12
13
/**
14
 * @package Commercetools\Core\Model\CustomField
15
 * @link https://docs.commercetools.com/http-api-projects-custom-fields.html#customfieldsdraft
16
 * @method FieldContainer getFields()
17
 * @method CustomFieldObjectDraft setFields(FieldContainer $fields = null)
18
 * @method TypeReference getType()
19
 * @method CustomFieldObjectDraft setType(TypeReference $type = null)
20
 */
21
class CustomFieldObjectDraft extends CustomFieldObject
22
{
23
    /**
24
     * @param string $typeKey
25
     * @param Context|callable $context
26
     * @return CustomFieldObjectDraft
27
     */
28 5
    public static function ofTypeKey($typeKey, $context = null)
29
    {
30 5
        $draft = static::of($context)->setType(TypeReference::ofKey($typeKey));
31
32 5
        return $draft;
33
    }
34
35
    /**
36
     * @param string $typeKey
37
     * @param FieldContainer $fields
38
     * @param Context|callable $context
39
     * @return CustomFieldObjectDraft
40
     */
41 3
    public static function ofTypeKeyAndFields($typeKey, FieldContainer $fields, $context = null)
42
    {
43 3
        return static::of($context)
44 3
            ->setType(TypeReference::ofKey($typeKey))
45 3
            ->setFields($fields);
46
    }
47
48
    /**
49
     * @param string $typeId
50
     * @param Context|callable $context
51
     * @return CustomFieldObjectDraft
52
     */
53
    public static function ofTypeId($typeId, $context = null)
54
    {
55
        $draft = static::of($context)->setType(TypeReference::ofId($typeId));
56
57
        return $draft;
58
    }
59
60
    /**
61
     * @param TypeReference $type
62
     * @param Context|callable $context
63
     * @return CustomFieldObjectDraft
64
     */
65 3
    public static function ofType(TypeReference $type, $context = null)
66
    {
67 3
        $draft = static::of($context)->setType($type);
68
69 3
        return $draft;
70
    }
71
72
    /**
73
     * @param TypeReference $type
74
     * @param FieldContainer $fields
75
     * @param Context|callable $context
76
     * @return CustomFieldObjectDraft
77
     */
78 1
    public static function ofTypeAndFields(TypeReference $type, FieldContainer $fields, $context = null)
79
    {
80 1
        return static::of($context)
81 1
            ->setType($type)
82 1
            ->setFields($fields);
83
    }
84
}
85