Completed
Push — master ( 461e07...b4459a )
by Alexandr
03:37
created

AbstractEnumType   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 59
Duplicated Lines 30.51 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 88.89%

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 11
c 5
b 1
f 1
lcom 1
cbo 4
dl 18
loc 59
rs 10
ccs 16
cts 18
cp 0.8889

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getKind() 0 4 1
A isValidValue() 0 4 1
getValues() 0 1 ?
A build() 0 1 1
A serialize() 8 8 3
A resolve() 10 10 3

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
 * Date: 07.12.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\GraphQL\Type\Object;
9
10
11
use Youshido\GraphQL\Type\AbstractType;
12
use Youshido\GraphQL\Type\Config\Object\EnumTypeConfig;
13
use Youshido\GraphQL\Type\Traits\AutoNameTrait;
14
use Youshido\GraphQL\Type\TypeMap;
15
16
abstract class AbstractEnumType extends AbstractType
17
{
18
    use AutoNameTrait;
19
    /**
20
     * ObjectType constructor.
21
     * @param $config
22
     */
23 9
    public function __construct($config = [])
24
    {
25 9
        if (empty($config)) {
26 9
            $config['name']   = $this->getName();
27 9
            $config['values'] = $this->getValues();
28
        }
29
30 9
        $this->config = new EnumTypeConfig($config, $this);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Youshido\GraphQL\Ty...eConfig($config, $this) of type object<Youshido\GraphQL\...\Object\EnumTypeConfig> is incompatible with the declared type object<Youshido\GraphQL\...\InputObjectTypeConfig> of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
31 9
    }
32
33
    /**
34
     * @return String predefined type kind
35
     */
36 6
    public function getKind()
37
    {
38 6
        return TypeMap::KIND_ENUM;
39
    }
40
41
    /**
42
     * @param $value mixed
43
     *
44
     * @return bool
45
     */
46
    public function isValidValue($value)
47
    {
48
        return in_array($value, array_map(function ($item) { return $item['value']; }, $this->getConfig()->get('values')));
49
    }
50
51
    abstract public function getValues();
52
53
    public function build($config) {}
54
55 1 View Code Duplication
    public function serialize($value)
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...
56
    {
57 1
        foreach ($this->getConfig()->get('values') as $valueItem) {
58 1
            if ($value == $valueItem['name']) {
59 1
                return $valueItem['value'];
60
            }
61
        }
62
    }
63
64 1 View Code Duplication
    public function resolve($value)
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...
65
    {
66 1
        foreach ($this->getConfig()->get('values') as $valueItem) {
67 1
            if ($value == $valueItem['value']) {
68 1
                return $valueItem['name'];
69
            }
70
        }
71
72
        return null;
73
    }
74
}
75