Conditions | 1 |
Paths | 1 |
Total Lines | 66 |
Code Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
21 | public function testReplace() |
||
22 | { |
||
23 | $input = <<<'STRING' |
||
24 | <?php |
||
25 | |||
26 | namespace Foo; |
||
27 | |||
28 | use PHPExcel; |
||
29 | use PHPExcel_Worksheet; |
||
30 | |||
31 | class Bar |
||
32 | { |
||
33 | /** |
||
34 | * @param PHPExcel $workbook |
||
35 | * @param PHPExcel_Worksheet $sheet |
||
36 | * |
||
37 | * @return string |
||
38 | */ |
||
39 | public function baz(PHPExcel $workbook, PHPExcel_Worksheet $sheet) |
||
40 | { |
||
41 | PHPExcel::class; |
||
42 | \PHPExcel::class; |
||
43 | $PHPExcel->do(); |
||
44 | $fooobjPHPExcel->do(); |
||
45 | $objPHPExcel->do(); |
||
46 | $this->objPHPExcel->do(); |
||
47 | $this->PHPExcel->do(); |
||
48 | |||
49 | return \PHPExcel_Cell::stringFromColumnIndex(9); |
||
50 | } |
||
51 | } |
||
52 | STRING; |
||
53 | |||
54 | $expected = <<<'STRING' |
||
55 | <?php |
||
56 | |||
57 | namespace Foo; |
||
58 | |||
59 | use \PhpOffice\PhpSpreadsheet\Spreadsheet; |
||
60 | use \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; |
||
61 | |||
62 | class Bar |
||
63 | { |
||
64 | /** |
||
65 | * @param \PhpOffice\PhpSpreadsheet\Spreadsheet $workbook |
||
66 | * @param \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $sheet |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | public function baz(\PhpOffice\PhpSpreadsheet\Spreadsheet $workbook, \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $sheet) |
||
71 | { |
||
72 | \PhpOffice\PhpSpreadsheet\Spreadsheet::class; |
||
73 | \PhpOffice\PhpSpreadsheet\Spreadsheet::class; |
||
74 | $PHPExcel->do(); |
||
75 | $fooobjPHPExcel->do(); |
||
76 | $objPHPExcel->do(); |
||
77 | $this->objPHPExcel->do(); |
||
78 | $this->PHPExcel->do(); |
||
79 | |||
80 | return \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex(9); |
||
81 | } |
||
82 | } |
||
83 | STRING; |
||
84 | |||
85 | $migrator = new Migrator(); |
||
86 | self::assertSame($expected, $migrator->replace($input)); |
||
87 | } |
||
89 |