Conditions | 2 |
Paths | 2 |
Total Lines | 56 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | 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 |
||
29 | #[DataProvider('providerCopyClone')] |
||
30 | public function testCopyClone(string $type): void |
||
31 | { |
||
32 | $this->spreadsheet = new Spreadsheet(); |
||
33 | $sheet = $this->spreadsheet->getActiveSheet(); |
||
34 | $sheet->setTitle('original'); |
||
35 | $sheet->getStyle('A1')->getFont()->setName('font1'); |
||
36 | $sheet->getStyle('A2')->getFont()->setName('font2'); |
||
37 | $sheet->getStyle('A3')->getFont()->setName('font3'); |
||
38 | $sheet->getStyle('B1')->getFont()->setName('font1'); |
||
39 | $sheet->getStyle('B2')->getFont()->setName('font2'); |
||
40 | $sheet->getCell('A1')->setValue('this is a1'); |
||
41 | $sheet->getCell('A2')->setValue('this is a2'); |
||
42 | $sheet->getCell('A3')->setValue('this is a3'); |
||
43 | $sheet->getCell('B1')->setValue('this is b1'); |
||
44 | $sheet->getCell('B2')->setValue('this is b2'); |
||
45 | self::assertSame('font1', $sheet->getStyle('A1')->getFont()->getName()); |
||
46 | $sheet->setSelectedCells('A3'); |
||
47 | if ($type === 'copy') { |
||
48 | $this->spreadsheet2 = $this->spreadsheet->copy(); |
||
49 | } else { |
||
50 | $this->spreadsheet2 = clone $this->spreadsheet; |
||
51 | } |
||
52 | self::assertSame($this->spreadsheet, $this->spreadsheet->getCalculationEngine()?->getSpreadsheet()); |
||
53 | self::assertSame($this->spreadsheet2, $this->spreadsheet2->getCalculationEngine()?->getSpreadsheet()); |
||
54 | self::assertSame('A3', $sheet->getSelectedCells()); |
||
55 | $copysheet = $this->spreadsheet2->getActiveSheet(); |
||
56 | self::assertSame('A3', $copysheet->getSelectedCells()); |
||
57 | self::assertSame('original', $copysheet->getTitle()); |
||
58 | $copysheet->setTitle('unoriginal'); |
||
59 | self::assertSame('original', $sheet->getTitle()); |
||
60 | self::assertSame('unoriginal', $copysheet->getTitle()); |
||
61 | $copysheet->getStyle('A2')->getFont()->setName('font12'); |
||
62 | $copysheet->getCell('A2')->setValue('this was a2'); |
||
63 | |||
64 | self::assertSame('font1', $sheet->getStyle('A1')->getFont()->getName()); |
||
65 | self::assertSame('font2', $sheet->getStyle('A2')->getFont()->getName()); |
||
66 | self::assertSame('font3', $sheet->getStyle('A3')->getFont()->getName()); |
||
67 | self::assertSame('font1', $sheet->getStyle('B1')->getFont()->getName()); |
||
68 | self::assertSame('font2', $sheet->getStyle('B2')->getFont()->getName()); |
||
69 | self::assertSame('this is a1', $sheet->getCell('A1')->getValue()); |
||
70 | self::assertSame('this is a2', $sheet->getCell('A2')->getValue()); |
||
71 | self::assertSame('this is a3', $sheet->getCell('A3')->getValue()); |
||
72 | self::assertSame('this is b1', $sheet->getCell('B1')->getValue()); |
||
73 | self::assertSame('this is b2', $sheet->getCell('B2')->getValue()); |
||
74 | |||
75 | self::assertSame('font1', $copysheet->getStyle('A1')->getFont()->getName()); |
||
76 | self::assertSame('font12', $copysheet->getStyle('A2')->getFont()->getName()); |
||
77 | self::assertSame('font3', $copysheet->getStyle('A3')->getFont()->getName()); |
||
78 | self::assertSame('font1', $copysheet->getStyle('B1')->getFont()->getName()); |
||
79 | self::assertSame('font2', $copysheet->getStyle('B2')->getFont()->getName()); |
||
80 | self::assertSame('this is a1', $copysheet->getCell('A1')->getValue()); |
||
81 | self::assertSame('this was a2', $copysheet->getCell('A2')->getValue()); |
||
82 | self::assertSame('this is a3', $copysheet->getCell('A3')->getValue()); |
||
83 | self::assertSame('this is b1', $copysheet->getCell('B1')->getValue()); |
||
84 | self::assertSame('this is b2', $copysheet->getCell('B2')->getValue()); |
||
85 | } |
||
153 |