Completed
Pull Request — master (#129)
by Pieter
03:36
created

FeatureNode   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 230
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 0

Test Coverage

Coverage 90.7%

Importance

Changes 0
Metric Value
wmc 17
lcom 4
cbo 0
dl 0
loc 230
ccs 39
cts 43
cp 0.907
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 25 2
A getNodeType() 0 4 1
A getTitle() 0 4 1
A hasDescription() 0 4 1
A getDescription() 0 4 1
A hasTag() 0 4 1
A hasTags() 0 4 1
A getTags() 0 4 1
A hasBackground() 0 4 1
A getBackground() 0 4 1
A hasScenarios() 0 4 1
A getScenarios() 0 4 1
A getKeyword() 0 4 1
A getLanguage() 0 4 1
A getFile() 0 4 1
A getLine() 0 4 1
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 Feature.
15
 *
16
 * @author Konstantin Kudryashov <[email protected]>
17
 */
18
class FeatureNode implements KeywordNodeInterface, TaggedNodeInterface
19
{
20
    /**
21
     * @var null|string
22
     */
23
    private $title;
24
    /**
25
     * @var null|string
26
     */
27
    private $description;
28
    /**
29
     * @var string[]
30
     */
31
    private $tags = array();
32
    /**
33
     * @var null|BackgroundNode
34
     */
35
    private $background;
36
    /**
37
     * @var ScenarioInterface[]
38
     */
39
    private $scenarios = array();
40
    /**
41
     * @var string
42
     */
43
    private $keyword;
44
    /**
45
     * @var string
46
     */
47
    private $language;
48
    /**
49
     * @var null|string
50
     */
51
    private $file;
52
    /**
53
     * @var integer
54
     */
55
    private $line;
56
57
    /**
58
     * Initializes feature.
59
     *
60
     * @param null|string         $title
61
     * @param null|string         $description
62
     * @param string[]            $tags
63
     * @param null|BackgroundNode $background
64
     * @param ScenarioInterface[] $scenarios
65
     * @param string              $keyword
66
     * @param string              $language
67
     * @param null|string         $file        The absolute path to the feature file.
68
     * @param integer             $line
69
     */
70 80
    public function __construct(
71
        $title,
72
        $description,
73
        array $tags,
74
        BackgroundNode $background = null,
75
        array $scenarios,
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
76
        $keyword,
77
        $language,
78
        $file,
79
        $line
80
    ) {
81
        // Verify that the feature file is an absolute path.
82 80
        if (realpath($file) === FALSE) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected false, but found FALSE.
Loading history...
83 2
            throw new \InvalidArgumentException('The file should be an absolute path.');
84
        }
85 79
        $this->title = $title;
86 79
        $this->description = $description;
87 79
        $this->tags = $tags;
88 79
        $this->background = $background;
89 79
        $this->scenarios = $scenarios;
90 79
        $this->keyword = $keyword;
91 79
        $this->language = $language;
92 79
        $this->file = $file;
93 79
        $this->line = $line;
94 79
    }
95
96
    /**
97
     * Returns node type string
98
     *
99
     * @return string
100
     */
101 1
    public function getNodeType()
102
    {
103 1
        return 'Feature';
104
    }
105
106
    /**
107
     * Returns feature title.
108
     *
109
     * @return null|string
110
     */
111 44
    public function getTitle()
112
    {
113 44
        return $this->title;
114
    }
115
116
    /**
117
     * Checks if feature has a description.
118
     *
119
     * @return Boolean
120
     */
121
    public function hasDescription()
122
    {
123
        return !empty($this->description);
124
    }
125
126
    /**
127
     * Returns feature description.
128
     *
129
     * @return null|string
130
     */
131 45
    public function getDescription()
132
    {
133 45
        return $this->description;
134
    }
135
136
    /**
137
     * Checks if feature is tagged with tag.
138
     *
139
     * @param string $tag
140
     *
141
     * @return Boolean
142
     */
143
    public function hasTag($tag)
144
    {
145
        return in_array($tag, $this->tags);
146
    }
147
148
    /**
149
     * Checks if feature has tags.
150
     *
151
     * @return Boolean
152
     */
153 2
    public function hasTags()
154
    {
155 2
        return 0 < count($this->tags);
156
    }
157
158
    /**
159
     * Returns feature tags.
160
     *
161
     * @return string[]
162
     */
163 43
    public function getTags()
164
    {
165 43
        return $this->tags;
166
    }
167
168
    /**
169
     * Checks if feature has background.
170
     *
171
     * @return Boolean
172
     */
173 1
    public function hasBackground()
174
    {
175 1
        return null !== $this->background;
176
    }
177
178
    /**
179
     * Returns feature background.
180
     *
181
     * @return null|BackgroundNode
182
     */
183 43
    public function getBackground()
184
    {
185 43
        return $this->background;
186
    }
187
188
    /**
189
     * Checks if feature has scenarios.
190
     *
191
     * @return Boolean
192
     */
193 2
    public function hasScenarios()
194
    {
195 2
        return 0 < count($this->scenarios);
196
    }
197
198
    /**
199
     * Returns feature scenarios.
200
     *
201
     * @return ScenarioInterface[]
202
     */
203 46
    public function getScenarios()
204
    {
205 46
        return $this->scenarios;
206
    }
207
208
    /**
209
     * Returns feature keyword.
210
     *
211
     * @return string
212
     */
213 40
    public function getKeyword()
214
    {
215 40
        return $this->keyword;
216
    }
217
218
    /**
219
     * Returns feature language.
220
     *
221
     * @return string
222
     */
223 41
    public function getLanguage()
224
    {
225 41
        return $this->language;
226
    }
227
228
    /**
229
     * Returns feature file as an absolute path.
230
     *
231
     * @return null|string
232
     */
233 11
    public function getFile()
234
    {
235 11
        return $this->file;
236
    }
237
238
    /**
239
     * Returns feature declaration line number.
240
     *
241
     * @return integer
242
     */
243 48
    public function getLine()
244
    {
245 48
        return $this->line;
246
    }
247
}
248