Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
Code Lines | 46 |
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 |
||
58 | public function testChinese() |
||
59 | { |
||
60 | $input = [ |
||
61 | 'header' => [ |
||
62 | 'prodName' => '@(#) IBM SPSS STATISTICS 64-bit Macintosh 23.0.0.0', |
||
63 | 'creationDate' => '05 Oct 18', |
||
64 | 'creationTime' => '01:36:53', |
||
65 | 'weightIndex' => 0, |
||
66 | ], |
||
67 | 'variables' => [ |
||
68 | new Variable('test1', [ |
||
69 | 'format' => Variable::FORMAT_TYPE_F, |
||
70 | 'width' => 4, |
||
71 | 'decimals' => 2, |
||
72 | 'label' => 'test', |
||
73 | 'values' => [ |
||
74 | 1 => '1测试中文标签1', |
||
75 | 2 => '2测试中文标签2', |
||
76 | ], |
||
77 | 'missing' => [], |
||
78 | 'columns' => 5, |
||
79 | 'alignment' => Variable::ALIGN_RIGHT, |
||
80 | 'measure' => Variable::MEASURE_SCALE, |
||
81 | 'attributes' => [ |
||
82 | '$@Role' => Variable::ROLE_PARTITION, |
||
83 | ], |
||
84 | 'data' => [1, 1, 1], |
||
85 | ]), |
||
86 | new Variable('test2', [ |
||
87 | 'format' => Variable::FORMAT_TYPE_A, |
||
88 | 'width' => 100, |
||
89 | 'label' => 'test', |
||
90 | 'columns' => 100, |
||
91 | 'alignment' => Variable::ALIGN_LEFT, |
||
92 | 'measure' => Variable::MEASURE_NOMINAL, |
||
93 | 'attributes' => [ |
||
94 | '$@Role' => Variable::ROLE_SPLIT, |
||
95 | ], |
||
96 | 'data' => [ |
||
97 | '测试中文数据1', |
||
98 | '测试中文数据2', |
||
99 | '测试中文数据3' |
||
100 | ], |
||
101 | ]), |
||
102 | ], |
||
103 | ]; |
||
104 | |||
105 | $writer = new Writer($input); |
||
106 | |||
107 | // Uncomment if you want to really save and check the resulting file in SPSS |
||
108 | //$writer->save('chinese1.sav'); |
||
109 | $buffer = $writer->getBuffer(); |
||
110 | $buffer->rewind(); |
||
111 | |||
112 | $reader = Reader::fromString($buffer->getStream())->read(); |
||
113 | $expected[0][0] = $input['variables'][0]->data[0]; |
||
114 | $expected[0][1] = $input['variables'][1]->data[0]; |
||
115 | $expected[1][0] = $input['variables'][0]->data[1]; |
||
116 | $expected[1][1] = $input['variables'][1]->data[1]; |
||
117 | $expected[2][0] = $input['variables'][0]->data[2]; |
||
118 | $expected[2][1] = $input['variables'][1]->data[2]; |
||
119 | $this->assertEquals($expected, $reader->data); |
||
120 | } |
||
123 |