Completed
Push — develop ( f876c4...3b7fce )
by
unknown
10:26
created

ResourceIdentifier   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 17.02 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 80%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 1
dl 8
loc 47
ccs 12
cts 15
cp 0.8
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fieldDefinitions() 8 8 1
A ofTypeAndId() 0 5 1
A ofTypeAndKey() 0 5 1
A jsonSerialize() 0 7 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 @ct-jensschulze <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Common;
7
8
/**
9
 * @package Commercetools\Core\Model\Common
10
 *
11
 * @method string getTypeId()
12
 * @method ResourceIdentifier setTypeId(string $typeId = null)
13
 * @method string getId()
14
 * @method ResourceIdentifier setId(string $id = null)
15
 * @method string getKey()
16
 * @method ResourceIdentifier setKey(string $key = null)
17
 */
18
abstract class ResourceIdentifier extends JsonObject
19
{
20
    const TYPE_ID = 'typeId';
21
    const ID = 'id';
22
    const KEY = 'key';
23
24 65 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...
25
    {
26
        return [
27 65
            static::TYPE_ID => [self::TYPE => 'string'],
28 65
            static::ID => [self::TYPE => 'string'],
29 65
            static::KEY => [self::TYPE => 'string']
30 65
        ];
31
    }
32
33
    /**
34
     * @param $type
35
     * @param $id
36
     * @param Context|callable $context
37
     * @return Reference
38
     */
39 70
    public static function ofTypeAndId($type, $id, $context = null)
40
    {
41 70
        $reference = static::of($context);
42 70
        return $reference->setTypeId($type)->setId($id);
43
    }
44
45
    /**
46
     * @param $type
47
     * @param $key
48
     * @param Context|callable $context
49
     * @return Reference
50
     */
51
    public static function ofTypeAndKey($type, $key, $context = null)
52
    {
53
        $reference = static::of($context);
54
        return $reference->setTypeId($type)->setKey($key);
55
    }
56
57 3
    public function jsonSerialize()
58
    {
59 3
        $data = parent::jsonSerialize();
60 3
        unset($data['obj']);
61
62 3
        return $data;
63
    }
64
}
65