Completed
Push — master ( b4459a...5882cd )
by Alexandr
03:37
created

Field   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 79
Duplicated Lines 12.66 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 57.14%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 10
c 5
b 0
f 1
lcom 1
cbo 2
dl 10
loc 79
rs 10
ccs 16
cts 28
cp 0.5714

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getName() 0 4 1
A setName() 0 4 1
A getAlias() 0 4 1
A setAlias() 0 4 1
A hasArguments() 0 4 1
A getArguments() 0 4 1
A addArgument() 0 4 1
A getKeyValueArguments() 10 10 2

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: 23.11.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\GraphQL\Parser\Ast;
9
10
11
class Field
12
{
13
    /** @var string */
14
    private $name;
15
16
    /** @var null|string */
17
    private $alias = null;
18
19
    /** @var Argument[] */
20
    protected $arguments;
21
22 36
    public function __construct($name, $alias = null, $arguments = [])
23
    {
24 36
        $this->name  = $name;
25 36
        $this->alias = $alias;
26 36
        $this->arguments = $arguments;
27 36
    }
28
29
    /**
30
     * @return string
31
     */
32 17
    public function getName()
33
    {
34 17
        return $this->name;
35
    }
36
37
    /**
38
     * @param string $name
39
     */
40
    public function setName($name)
41
    {
42
        $this->name = $name;
43
    }
44
45
    /**
46
     * @return null|string
47
     */
48 17
    public function getAlias()
49
    {
50 17
        return $this->alias;
51
    }
52
53
    /**
54
     * @param null|string $alias
55
     */
56
    public function setAlias($alias)
57
    {
58
        $this->alias = $alias;
59
    }
60
61
    public function hasArguments()
62
    {
63
        return (bool)count($this->arguments);
64
    }
65
66
    /**
67
     * @return Argument[]
68
     */
69 1
    public function getArguments()
70
    {
71 1
        return $this->arguments;
72
    }
73
74
    public function addArgument(Argument $argument)
75
    {
76
        $this->arguments[$argument->getName()] = $argument;
77
    }
78
79 1 View Code Duplication
    public function getKeyValueArguments()
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...
80
    {
81 1
        $arguments = [];
82
83 1
        foreach ($this->getArguments() as $argument) {
84
            $arguments[$argument->getName()] = $argument->getValue()->getValue();
85 1
        }
86
87 1
        return $arguments;
88
    }
89
}