Completed
Push — master ( e069d8...e9704f )
by Alexandr
03:36
created

AbstractField   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 70
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 17
Bugs 7 Features 0
Metric Value
wmc 11
c 17
b 7
f 0
lcom 1
cbo 5
dl 14
loc 70
ccs 26
cts 26
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 14 14 3
getType() 0 1 ?
A build() 0 3 1
A setType() 0 4 1
A resolve() 0 4 1
A getResolveFunction() 0 10 3
A isDeprecated() 0 4 1
A getDeprecationReason() 0 4 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
 * Date: 13.05.16
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\GraphQL\Field;
9
10
use Youshido\GraphQL\Config\Field\FieldConfig;
11
use Youshido\GraphQL\Execution\ResolveInfo;
12
use Youshido\GraphQL\Type\Object\AbstractObjectType;
13
use Youshido\GraphQL\Type\Traits\AutoNameTrait;
14
use Youshido\GraphQL\Type\Traits\FieldsArgumentsAwareObjectTrait;
15
use Youshido\GraphQL\Type\TypeFactory;
16
use Youshido\GraphQL\Type\TypeService;
17
18
abstract class AbstractField implements FieldInterface
19
{
20
21
    use FieldsArgumentsAwareObjectTrait, AutoNameTrait;
22
23
    protected $isFinal = false;
24
25
    protected $_resolve_cache = null;
26
27 64 View Code Duplication
    public function   __construct(array $config = [])
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...
28
    {
29 64
        if (empty($config['type'])) {
30 30
            $config['type'] = $this->getType();
31 30
            $config['name'] = $this->getName();
32
        }
33
34 64
        if (TypeService::isScalarType($config['type'])) {
35 56
            $config['type'] = TypeFactory::getScalarType($config['type']);
36
        }
37
38 64
        $this->config = new FieldConfig($config, $this, $this->isFinal);
39 62
        $this->build($this->config);
40 62
    }
41
42
    /**
43
     * @return AbstractObjectType
44
     */
45
    abstract public function getType();
46
47 61
    public function build(FieldConfig $config)
48
    {
49 61
    }
50
51 1
    public function setType($type)
52
    {
53 1
        $this->getConfig()->set('type', $type);
54 1
    }
55
56
    /**
57
     * @param             $value
58
     * @param array       $args
59
     * @param ResolveInfo $info
60
     * @return mixed
61
     */
62 3
    public function resolve($value, array $args, ResolveInfo $info)
63
    {
64 3
        return null;
65
    }
66
67 19
    public function getResolveFunction()
68
    {
69 19
        if ($this->_resolve_cache === null) {
70 19
            $this->_resolve_cache = $this->getConfig()->getResolveFunction();
71 19
            if (!$this->_resolve_cache) {
72 19
                $this->_resolve_cache = false;
73
            }
74
        }
75 19
        return $this->_resolve_cache;
76
    }
77
78 3
    public function isDeprecated()
79
    {
80 3
        return $this->getConfigValue('isDeprecated');
81
    }
82
83 3
    public function getDeprecationReason()
84
    {
85 3
        return $this->getConfigValue('deprecationReason');
86
    }
87
}
88