Completed
Push — master ( d52ee7...e7842c )
by Alexandr
03:54
created

AbstractInputField   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 35 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 2 Features 0
Metric Value
wmc 5
c 7
b 2
f 0
lcom 1
cbo 5
dl 14
loc 40
rs 10
ccs 15
cts 15
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 14 14 3
A build() 0 4 1
getType() 0 1 ?
A getDefaultValue() 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
11
use Youshido\GraphQL\Config\Field\InputFieldConfig;
12
use Youshido\GraphQL\Type\InputObject\AbstractInputObjectType;
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 AbstractInputField implements FieldInterface
19
{
20
21
    use FieldsArgumentsAwareObjectTrait, AutoNameTrait;
22
23
    protected $isFinal = false;
24
25 33 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...
26
    {
27 33
        if (empty($config['type'])) {
28 1
            $config['type'] = $this->getType();
29 1
            $config['name'] = $this->getName();
30 1
        }
31
32 33
        if (TypeService::isScalarType($config['type'])) {
33 22
            $config['type'] = TypeFactory::getScalarType($config['type']);
34 22
        }
35
36 33
        $this->config = new InputFieldConfig($config, $this, $this->isFinal);
37 31
        $this->build($this->config);
38 31
    }
39
40 31
    public function build(InputFieldConfig $config)
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
    {
42
43 31
    }
44
45
    /**
46
     * @return AbstractInputObjectType
47
     */
48
    abstract public function getType();
49
50 3
    public function getDefaultValue()
51
    {
52 3
        return $this->config->getDefaultValue();
0 ignored issues
show
Documentation Bug introduced by
The method getDefaultValue does not exist on object<Youshido\GraphQL\Config\AbstractConfig>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
53
    }
54
55
    //todo: think about serialize, parseValue methods
56
57
}
58