Completed
Push — develop ( 79f8cb...57f680 )
by Jens
09:18
created

CustomFieldObjectDraft   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 15.22 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 53.85%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 1
cbo 2
dl 7
loc 46
ccs 7
cts 13
cp 0.5385
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fieldDefinitions() 7 7 1
A ofTypeKey() 0 6 1
A ofTypeId() 0 6 1
A ofType() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * @author @jayS-de <[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://dev.commercetools.com/http-api-projects-custom-fields.html#new-custom-fields
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 JsonObject
22
{
23 3 View Code Duplication
    public function fieldDefinitions()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        return [
26 3
            'type' => [static::TYPE => '\Commercetools\Core\Model\Type\TypeReference'],
27 3
            'fields' => [static::TYPE => '\Commercetools\Core\Model\CustomField\FieldContainer']
28 3
        ];
29
    }
30
31
    /**
32
     * @param $typeKey
33
     * @param Context|callable $context
34
     * @return CustomFieldObjectDraft
35
     */
36
    public static function ofTypeKey($typeKey, $context = null)
37
    {
38
        $draft = static::of($context)->setType(TypeReference::ofKey($typeKey));
39
40
        return $draft;
41
    }
42
43
    /**
44
     * @param string $typeId
45
     * @param Context|callable $context
46
     * @return CustomFieldObjectDraft
47
     */
48
    public static function ofTypeId($typeId, $context = null)
49
    {
50
        $draft = static::of($context)->setType(TypeReference::ofId($typeId));
51
52
        return $draft;
53
    }
54
55
    /**
56
     * @param TypeReference $type
57
     * @param Context|callable $context
58
     * @return CustomFieldObjectDraft
59
     */
60 3
    public static function ofType(TypeReference $type, $context = null)
61
    {
62 3
        $draft = static::of($context)->setType($type);
63
64 3
        return $draft;
65
    }
66
}
67