Completed
Pull Request — master (#162)
by
unknown
02:07
created

BackgroundNode   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 121
Duplicated Lines 6.61 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 73.91%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 0
dl 8
loc 121
ccs 17
cts 23
cp 0.7391
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 1
A getNodeType() 0 4 1
A getTitle() 0 4 1
A hasSteps() 0 4 1
A getSteps() 0 4 1
A getKeyword() 0 4 1
A getLine() 0 4 1
A hasExamples() 0 4 1
A getExamples() 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
/*
4
 * This file is part of the Behat Gherkin.
5
 * (c) Konstantin Kudryashov <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Behat\Gherkin\Node;
12
13
/**
14
 * Represents Gherkin Background.
15
 *
16
 * @author Konstantin Kudryashov <[email protected]>
17
 */
18
class BackgroundNode implements ScenarioLikeInterface
19
{
20
    /**
21
     * @var string
22
     */
23
    private $title;
24
    /**
25
     * @var StepNode[]
26
     */
27
    private $steps = array();
28
    /**
29
     * @var string
30
     */
31
    private $keyword;
32
    /**
33
     * @var integer
34
     */
35
    private $line;
36
    /**
37
     * @var ExampleTableNode
38
     */
39
    private $exampleTable;
40
41
    /**
42
     * Initializes background.
43
     *
44
     * @param null|string $title
45
     * @param StepNode[]  $steps
46
     * @param string      $keyword
47
     * @param integer     $line
48
     * @param ExampleTableNode $exampleTable
49
     */
50 196 View Code Duplication
    public function __construct($title, array $steps, $keyword, $line, $exampleTable=null)
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...
51
    {
52 196
        $this->title = $title;
53 196
        $this->steps = $steps;
54 196
        $this->keyword = $keyword;
55 196
        $this->line = $line;
56 196
        $this->exampleTable = $exampleTable;
57 196
    }
58
59
    /**
60
     * Returns node type string
61
     *
62
     * @return string
63
     */
64
    public function getNodeType()
65
    {
66
        return 'Background';
67
    }
68
69
    /**
70
     * Returns background title.
71
     *
72
     * @return null|string
73
     */
74
    public function getTitle()
75
    {
76
        return $this->title;
77
    }
78
79
    /**
80
     * Checks if background has steps.
81
     *
82
     * @return Boolean
83
     */
84 2
    public function hasSteps()
85
    {
86 2
        return 0 < count($this->steps);
87
    }
88
89
    /**
90
     * Returns background steps.
91
     *
92
     * @return StepNode[]
93
     */
94 2
    public function getSteps()
95
    {
96 2
        return $this->steps;
97
    }
98
99
    /**
100
     * Returns background keyword.
101
     *
102
     * @return string
103
     */
104
    public function getKeyword()
105
    {
106
        return $this->keyword;
107
    }
108
109
    /**
110
     * Returns background declaration line number.
111
     *
112
     * @return integer
113
     */
114 2
    public function getLine()
115
    {
116 2
        return $this->line;
117
    }
118
119
    /**
120
     * Returns if background has ExampleTable
121
     *
122
     * @return boolean
123
     */
124 2
    public function hasExamples()
125
    {
126 2
        return $this->exampleTable !== null;
127
    }
128
129
    /**
130
     * Returns if background has ExampleTable
131
     *
132
     * @return null|ExampleTableNode
133
     */
134 1
    public function getExamples()
135
    {
136 1
        return $this->exampleTable;
137
    }
138
}
139