Completed
Push — master ( 01d73e...c6357c )
by Juliette
03:01
created

dataGetFunctionCallParameters()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 104
Code Lines 71

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
c 4
b 1
f 0
dl 0
loc 104
rs 8.2857
cc 1
eloc 71
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Function parameter count test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Function parameters count function tests
11
 *
12
 * @uses    BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author  Juliette Reinders Folmer <[email protected]>
15
 */
16
class GetFunctionParametersTest extends BaseAbstractClassMethodTest
17
{
18
19
    public $filename = 'sniff-examples/utility-functions/get_function_parameters.php';
20
21
    /**
22
     * testGetFunctionCallParameters
23
     *
24
     * @group utilityFunctions
25
     *
26
     * @dataProvider dataGetFunctionCallParameters
27
     *
28
     * @param int    $stackPtr Stack pointer for a T_CLASS token in the test file.
29
     * @param string $expected The expected fully qualified class name.
30
     */
31
    public function testGetFunctionCallParameters($stackPtr, $expected)
32
    {
33
        $result = $this->helperClass->getFunctionCallParameters($this->_phpcsFile, $stackPtr);
34
        $this->assertSame($expected, $result);
35
    }
36
37
    /**
38
     * dataGetFunctionCallParameters
39
     *
40
     * @see testGetFunctionCallParameters()
41
     *
42
     * @return array
43
     */
44
    public function dataGetFunctionCallParameters()
45
    {
46
        return array(
47
            array(88, array(
48
                       1 => array(
49
                             'start' => 90,
50
                             'end'   => 91,
51
                             'raw'   => '1',
52
                            ),
53
                       2 => array(
54
                             'start' => 93,
55
                             'end'   => 94,
56
                             'raw'   => '2',
57
                            ),
58
                       3 => array(
59
                             'start' => 96,
60
                             'end'   => 97,
61
                             'raw'   => '3',
62
                            ),
63
                       4 => array(
64
                             'start' => 99,
65
                             'end'   => 100,
66
                             'raw'   => '4',
67
                            ),
68
                       5 => array(
69
                             'start' => 102,
70
                             'end'   => 103,
71
                             'raw'   => '5',
72
                            ),
73
                       6 => array(
74
                             'start' => 105,
75
                             'end'   => 106,
76
                             'raw'   => '6',
77
                            ),
78
                       7 => array(
79
                             'start' => 108,
80
                             'end'   => 110,
81
                             'raw'   => 'true',
82
                            ),
83
                      ),
84
85
            ),
86
            array(120, array(
87
                        1 => array(
88
                              'start' => 122,
89
                              'end'   => 129,
90
                              'raw'   => 'dirname( __FILE__ )',
91
                             ),
92
                       ),
93
            ),
94
            array(250, array(
95
                        1 => array(
96
                              'start' => 252,
97
                              'end'   => 252,
98
                              'raw'   => '$stHour',
99
                             ),
100
                        2 => array(
101
                              'start' => 254,
102
                              'end'   => 255,
103
                              'raw'   => '0',
104
                             ),
105
                        3 => array(
106
                              'start' => 257,
107
                              'end'   => 258,
108
                              'raw'   => '0',
109
                             ),
110
                        4 => array(
111
                              'start' => 260,
112
                              'end'   => 264,
113
                              'raw'   => '$arrStDt[0]',
114
                             ),
115
                        5 => array(
116
                              'start' => 266,
117
                              'end'   => 270,
118
                              'raw'   => '$arrStDt[1]',
119
                             ),
120
                        6 => array(
121
                              'start' => 272,
122
                              'end'   => 276,
123
                              'raw'   => '$arrStDt[2]',
124
                             ),
125
                       ),
126
127
            ),
128
            array(535, array(
129
                        1 => array(
130
                              'start' => 537,
131
                              'end'   => 540,
132
                              'raw'   => 'array()',
133
                             ),
134
                       ),
135
136
            ),
137
            array(577, array(
138
                        1 => array(
139
                              'start' => 579,
140
                              'end'   => 611,
141
                              'raw'   => '[\'a\' => $a,] + (isset($b) ? [\'b\' => $b,] : [])',
142
                             ),
143
                       ),
144
145
            ),
146
        );
147
    }
148
149
150
    /**
151
     * testGetFunctionCallParameter
152
     *
153
     * @group utilityFunctions
154
     *
155
     * @dataProvider dataGetFunctionCallParameter
156
     *
157
     * @param int    $stackPtr Stack pointer for a T_CLASS token in the test file.
158
     * @param string $expected The expected fully qualified class name.
159
     */
160
    public function testGetFunctionCallParameter($stackPtr, $paramPosition, $expected)
161
    {
162
        $result = $this->helperClass->getFunctionCallParameter($this->_phpcsFile, $stackPtr, $paramPosition);
163
        $this->assertSame($expected, $result);
164
    }
165
166
    /**
167
     * dataGetFunctionCallParameter
168
     *
169
     * @see testGetFunctionCallParameter()
170
     *
171
     * @return array
172
     */
173
    public function dataGetFunctionCallParameter()
174
    {
175
        return array(
176
            array(88, 4, array(
177
                          'start' => 99,
178
                          'end'   => 100,
179
                          'raw'   => '4',
180
                         ),
181
            ),
182
            array(120, 1, array(
183
                           'start' => 122,
184
                           'end'   => 129,
185
                           'raw'   => 'dirname( __FILE__ )',
186
                          ),
187
            ),
188
            array(250, 1, array(
189
                           'start' => 252,
190
                           'end'   => 252,
191
                           'raw'   => '$stHour',
192
                          ),
193
            ),
194
            array(250, 6, array(
195
                           'start' => 272,
196
                           'end'   => 276,
197
                           'raw'   => '$arrStDt[2]',
198
                          ),
199
            ),
200
        );
201
    }
202
203
204
    /**
205
     * testGetFunctionCallParameterCount
206
     *
207
     * @group utilityFunctions
208
     *
209
     * @dataProvider dataGetFunctionCallParameterCount
210
     *
211
     * @param int    $stackPtr Stack pointer for a T_CLASS token in the test file.
212
     * @param string $expected The expected fully qualified class name.
213
     */
214
    public function testGetFunctionCallParameterCount($stackPtr, $expected)
215
    {
216
        $result = $this->helperClass->getFunctionCallParameterCount($this->_phpcsFile, $stackPtr);
217
        $this->assertSame($expected, $result);
218
    }
219
220
    /**
221
     * dataGetFunctionCallParameterCount
222
     *
223
     * @see testGetFunctionCallParameterCount()
224
     *
225
     * @return array
226
     */
227
    public function dataGetFunctionCallParameterCount()
228
    {
229
        return array(
230
            array(5, 1),
231
            array(11, 2),
232
            array(22, 3),
233
            array(34, 4),
234
            array(49, 5),
235
            array(67, 6),
236
            array(88, 7),
237
            array(120, 1),
238
            array(135, 1),
239
            array(150, 1),
240
            array(164, 2),
241
            array(181, 1),
242
            array(194, 1),
243
            array(209, 1),
244
            array(228, 2),
245
            array(250, 6),
246
            array(281, 6),
247
            array(312, 6),
248
            array(351, 6),
249
            array(386, 6),
250
            array(420, 6),
251
            array(454, 6),
252
            array(499, 3),
253
            array(518, 1),
254
            array(535, 1),
255
256
            // Issue #211.
257
            array(551, 1),
258
            array(564, 1),
259
            array(577, 1),
260
            array(615, 1),
261
            array(660, 1),
262
            array(710, 1),
263
            array(761, 1),
264
            array(818, 1),
265
            array(874, 1),
266
            array(894, 1),
267
            array(910, 1),
268
            array(930, 1),
269
            array(964, 1),
270
            array(984, 1),
271
            array(1008, 1),
272
            array(1038, 1),
273
            array(1074, 1),
274
            array(1111, 1),
275
            array(1154, 1),
276
            array(1184, 1),
277
            array(1215, 1),
278
            array(1241, 1),
279
        );
280
    }
281
282
}
283