Completed
Pull Request — master (#129)
by Pieter
02:50
created

FeatureNode::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 14
cts 14
cp 1
rs 9.504
c 0
b 0
f 0
cc 3
nc 2
nop 9
crap 3

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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
use Symfony\Component\Filesystem\Filesystem;
14
15
/**
16
 * Represents Gherkin Feature.
17
 *
18
 * @author Konstantin Kudryashov <[email protected]>
19
 */
20
class FeatureNode implements KeywordNodeInterface, TaggedNodeInterface
21
{
22
    /**
23
     * @var null|string
24
     */
25
    private $title;
26
    /**
27
     * @var null|string
28
     */
29
    private $description;
30
    /**
31
     * @var string[]
32
     */
33
    private $tags = array();
34
    /**
35
     * @var null|BackgroundNode
36
     */
37
    private $background;
38
    /**
39
     * @var ScenarioInterface[]
40
     */
41
    private $scenarios = array();
42
    /**
43
     * @var string
44
     */
45
    private $keyword;
46
    /**
47
     * @var string
48
     */
49
    private $language;
50
    /**
51
     * @var null|string
52
     */
53
    private $file;
54
    /**
55
     * @var integer
56
     */
57
    private $line;
58
59
    /**
60
     * Initializes feature.
61
     *
62
     * @param null|string         $title
63
     * @param null|string         $description
64
     * @param string[]            $tags
65
     * @param null|BackgroundNode $background
66
     * @param ScenarioInterface[] $scenarios
67
     * @param string              $keyword
68
     * @param string              $language
69
     * @param null|string         $file        The absolute path to the feature file.
70
     * @param integer             $line
71
     */
72 268
    public function __construct(
73
        $title,
74
        $description,
75
        array $tags,
76
        BackgroundNode $background = null,
77
        array $scenarios,
78
        $keyword,
79
        $language,
80
        $file,
81
        $line
82
    ) {
83
        // Verify that the feature file is an absolute path.
84 268
        $filesystem = new Filesystem();
85 268
        if (!empty($file) && !$filesystem->isAbsolutePath($file)) {
86 188
            throw new \InvalidArgumentException('The file should be an absolute path.');
87
        }
88 80
        $this->title = $title;
89 80
        $this->description = $description;
90 80
        $this->tags = $tags;
91 80
        $this->background = $background;
92 80
        $this->scenarios = $scenarios;
93 80
        $this->keyword = $keyword;
94 80
        $this->language = $language;
95 80
        $this->file = $file;
96 80
        $this->line = $line;
97 80
    }
98
99
    /**
100
     * Returns node type string
101
     *
102
     * @return string
103
     */
104 1
    public function getNodeType()
105
    {
106 1
        return 'Feature';
107
    }
108
109
    /**
110
     * Returns feature title.
111
     *
112
     * @return null|string
113
     */
114 45
    public function getTitle()
115
    {
116 45
        return $this->title;
117
    }
118
119
    /**
120
     * Checks if feature has a description.
121
     *
122
     * @return Boolean
123
     */
124
    public function hasDescription()
125
    {
126
        return !empty($this->description);
127
    }
128
129
    /**
130
     * Returns feature description.
131
     *
132
     * @return null|string
133
     */
134 45
    public function getDescription()
135
    {
136 45
        return $this->description;
137
    }
138
139
    /**
140
     * Checks if feature is tagged with tag.
141
     *
142
     * @param string $tag
143
     *
144
     * @return Boolean
145
     */
146
    public function hasTag($tag)
147
    {
148
        return in_array($tag, $this->tags);
149
    }
150
151
    /**
152
     * Checks if feature has tags.
153
     *
154
     * @return Boolean
155
     */
156 2
    public function hasTags()
157
    {
158 2
        return 0 < count($this->tags);
159
    }
160
161
    /**
162
     * Returns feature tags.
163
     *
164
     * @return string[]
165
     */
166 43
    public function getTags()
167
    {
168 43
        return $this->tags;
169
    }
170
171
    /**
172
     * Checks if feature has background.
173
     *
174
     * @return Boolean
175
     */
176 1
    public function hasBackground()
177
    {
178 1
        return null !== $this->background;
179
    }
180
181
    /**
182
     * Returns feature background.
183
     *
184
     * @return null|BackgroundNode
185
     */
186 43
    public function getBackground()
187
    {
188 43
        return $this->background;
189
    }
190
191
    /**
192
     * Checks if feature has scenarios.
193
     *
194
     * @return Boolean
195
     */
196 2
    public function hasScenarios()
197
    {
198 2
        return 0 < count($this->scenarios);
199
    }
200
201
    /**
202
     * Returns feature scenarios.
203
     *
204
     * @return ScenarioInterface[]
205
     */
206 46
    public function getScenarios()
207
    {
208 46
        return $this->scenarios;
209
    }
210
211
    /**
212
     * Returns feature keyword.
213
     *
214
     * @return string
215
     */
216 40
    public function getKeyword()
217
    {
218 40
        return $this->keyword;
219
    }
220
221
    /**
222
     * Returns feature language.
223
     *
224
     * @return string
225
     */
226 41
    public function getLanguage()
227
    {
228 41
        return $this->language;
229
    }
230
231
    /**
232
     * Returns feature file as an absolute path.
233
     *
234
     * @return null|string
235
     */
236 13
    public function getFile()
237
    {
238 13
        return $this->file;
239
    }
240
241
    /**
242
     * Returns feature declaration line number.
243
     *
244
     * @return integer
245
     */
246 48
    public function getLine()
247
    {
248 48
        return $this->line;
249
    }
250
}
251