Completed
Pull Request — master (#150)
by Matt
02:45
created

FeatureNode::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 12
cts 12
cp 1
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 10
crap 1

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
/**
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 RuleNode[]
42
     */
43
    private $rules = array();
44
    /**
45
     * @var string
46
     */
47
    private $keyword;
48
    /**
49
     * @var string
50
     */
51
    private $language;
52
    /**
53
     * @var null|string
54
     */
55
    private $file;
56
    /**
57
     * @var integer
58
     */
59
    private $line;
60
61
    /**
62
     * Initializes feature.
63
     *
64
     * @param null|string         $title
65
     * @param null|string         $description
66
     * @param string[]            $tags
67
     * @param null|BackgroundNode $background
68
     * @param ScenarioInterface[] $scenarios
69
     * @param string              $keyword
70
     * @param string              $language
71
     * @param null|string         $file
72
     * @param integer             $line
73
     * @param RuleNode[]          $rules
74
     */
75 270
    public function __construct(
76
        $title,
77
        $description,
78
        array $tags,
79
        BackgroundNode $background = null,
80
        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...
81
        $keyword,
82
        $language,
83
        $file,
84
        $line,
85
        array $rules = array()
86
    ) {
87 270
        $this->title = $title;
88 270
        $this->description = $description;
89 270
        $this->tags = $tags;
90 270
        $this->background = $background;
91 270
        $this->scenarios = $scenarios;
92 270
        $this->keyword = $keyword;
93 270
        $this->language = $language;
94 270
        $this->file = $file;
95 270
        $this->line = $line;
96 270
        $this->rules = $rules;
97 270
    }
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 47
    public function getTitle()
115
    {
116 47
        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 46
    public function getDescription()
135
    {
136 46
        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 44
    public function getTags()
167
    {
168 44
        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 44
    public function getBackground()
187
    {
188 44
        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 47
    public function getScenarios()
207
    {
208 47
        return $this->scenarios;
209
    }
210
211
    /**
212
     * Returns rules
213
     *
214
     * @return RuleNode[]
215
     */
216 36
    public function getRules()
217
    {
218 36
        return $this->rules;
219
    }
220
221
    /**
222
     * Returns feature keyword.
223
     *
224
     * @return string
225
     */
226 41
    public function getKeyword()
227
    {
228 41
        return $this->keyword;
229
    }
230
231
    /**
232
     * Returns feature language.
233
     *
234
     * @return string
235
     */
236 43
    public function getLanguage()
237
    {
238 43
        return $this->language;
239
    }
240
241
    /**
242
     * Returns feature file.
243
     *
244
     * @return null|string
245
     */
246 13
    public function getFile()
247
    {
248 13
        return $this->file;
249
    }
250
251
    /**
252
     * Returns feature declaration line number.
253
     *
254
     * @return integer
255
     */
256 50
    public function getLine()
257
    {
258 50
        return $this->line;
259
    }
260
}
261