Conditions | 1 |
Paths | 1 |
Total Lines | 70 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
12 | public function testLongString() |
||
13 | { |
||
14 | $firstLong = str_repeat('1234567890', 300); |
||
15 | $secondLong = str_repeat('abcdefghij', 300); |
||
16 | $data = [ |
||
17 | 'header' => [ |
||
18 | 'prodName' => '@(#) IBM SPSS STATISTICS', |
||
19 | 'layoutCode' => 2, |
||
20 | 'creationDate' => '08 May 19', |
||
21 | 'creationTime' => '12:22:16', |
||
22 | ], |
||
23 | 'variables' => [ |
||
24 | [ |
||
25 | 'name' => 'LONGER1', |
||
26 | 'label' => 'long label1', |
||
27 | 'width' => 3000, |
||
28 | 'format' => Variable::FORMAT_TYPE_A, |
||
29 | 'attributes' => [ |
||
30 | '$@Role' => Variable::ROLE_INPUT, |
||
31 | ], |
||
32 | 'data' => [ |
||
33 | $firstLong, |
||
34 | $secondLong |
||
35 | ] |
||
36 | ], |
||
37 | [ |
||
38 | 'name' => 'LONGER2', |
||
39 | 'label' => 'long label2', |
||
40 | 'width' => 3000, |
||
41 | 'format' => Variable::FORMAT_TYPE_A, |
||
42 | 'attributes' => [ |
||
43 | '$@Role' => Variable::ROLE_INPUT, |
||
44 | ], |
||
45 | 'data' => [ |
||
46 | $firstLong, |
||
47 | $secondLong |
||
48 | ] |
||
49 | ], |
||
50 | [ |
||
51 | 'name' => 'short', |
||
52 | 'label' => 'short label', |
||
53 | 'format' => Variable::FORMAT_TYPE_A, |
||
54 | 'width' => 8, |
||
55 | 'attributes' => [ |
||
56 | '$@Role' => Variable::ROLE_INPUT, |
||
57 | ], |
||
58 | 'data' => [ |
||
59 | '12345678', |
||
60 | 'abcdefgh' |
||
61 | ], |
||
62 | ], |
||
63 | ], |
||
64 | ]; |
||
65 | $writer = new Writer($data); |
||
66 | |||
67 | // Uncomment if you want to really save and check the resulting file in SPSS |
||
68 | //$writer->save('longString.sav'); |
||
69 | |||
70 | $buffer = $writer->getBuffer(); |
||
71 | $buffer->rewind(); |
||
72 | |||
73 | $reader = Reader::fromString($buffer->getStream())->read(); |
||
|
|||
74 | |||
75 | $expected[0][0] = $data['variables'][0]['data'][0]; |
||
76 | $expected[0][1] = $data['variables'][1]['data'][0]; |
||
77 | $expected[0][2] = $data['variables'][2]['data'][0]; |
||
78 | $expected[1][0] = $data['variables'][0]['data'][1]; |
||
79 | $expected[1][1] = $data['variables'][1]['data'][1]; |
||
80 | $expected[1][2] = $data['variables'][2]['data'][1]; |
||
81 | $this->assertEquals($expected, $reader->data); |
||
82 | } |
||
85 |