Conditions | 1 |
Paths | 1 |
Total Lines | 87 |
Code Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
18 | public function testDisplayBlanksAs(): void |
||
19 | { |
||
20 | $spreadsheet = new Spreadsheet(); |
||
21 | $worksheet = $spreadsheet->getActiveSheet(); |
||
22 | $worksheet->fromArray( |
||
23 | [ |
||
24 | ['', 2010, 2011, 2012], |
||
25 | ['Q1', 12, 15, 21], |
||
26 | ['Q2', 56, 73, 86], |
||
27 | ['Q3', 52, 61, 69], |
||
28 | ['Q4', 30, 32, 0], |
||
29 | ] |
||
30 | ); |
||
31 | |||
32 | $dataSeriesLabels = [ |
||
33 | new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 |
||
34 | new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 |
||
35 | new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 |
||
36 | ]; |
||
37 | |||
38 | $xAxisTickValues = [ |
||
39 | new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 |
||
40 | ]; |
||
41 | |||
42 | $dataSeriesValues = [ |
||
43 | new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), |
||
44 | new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), |
||
45 | new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), |
||
46 | ]; |
||
47 | |||
48 | // Build the dataseries |
||
49 | $series = new DataSeries( |
||
50 | DataSeries::TYPE_AREACHART, // plotType |
||
51 | DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping |
||
52 | range(0, count($dataSeriesValues) - 1), // plotOrder |
||
53 | $dataSeriesLabels, // plotLabel |
||
54 | $xAxisTickValues, // plotCategory |
||
55 | $dataSeriesValues // plotValues |
||
56 | ); |
||
57 | |||
58 | $plotArea = new PlotArea(null, [$series]); |
||
59 | $legend = new ChartLegend(ChartLegend::POSITION_TOPRIGHT, null, false); |
||
60 | |||
61 | $title = new Title('Test %age-Stacked Area Chart'); |
||
62 | $yAxisLabel = new Title('Value ($k)'); |
||
63 | |||
64 | $chart1 = new Chart( |
||
65 | 'chart1', // name |
||
66 | $title, // title |
||
67 | $legend, // legend |
||
68 | $plotArea, // plotArea |
||
69 | true, // plotVisibleOnly |
||
70 | DataSeries::EMPTY_AS_GAP, // displayBlanksAs |
||
71 | null, // xAxisLabel |
||
72 | $yAxisLabel // yAxisLabel |
||
73 | ); |
||
74 | self::assertSame(DataSeries::EMPTY_AS_GAP, $chart1->getDisplayBlanksAs()); |
||
75 | $chart1->setDisplayBlanksAs(DataSeries::EMPTY_AS_ZERO); |
||
76 | self::assertSame(DataSeries::EMPTY_AS_ZERO, $chart1->getDisplayBlanksAs()); |
||
77 | $chart1->setDisplayBlanksAs('0'); |
||
78 | self::assertSame(DataSeries::EMPTY_AS_GAP, $chart1->getDisplayBlanksAs(), 'invalid setting converted to default'); |
||
79 | |||
80 | $chart2 = new Chart( |
||
81 | 'chart2', // name |
||
82 | $title, // title |
||
83 | $legend, // legend |
||
84 | $plotArea, // plotArea |
||
85 | true, // plotVisibleOnly |
||
86 | DataSeries::EMPTY_AS_SPAN, // displayBlanksAs |
||
87 | null, // xAxisLabel |
||
88 | $yAxisLabel // yAxisLabel |
||
89 | ); |
||
90 | self::assertSame(DataSeries::EMPTY_AS_SPAN, $chart2->getDisplayBlanksAs()); |
||
91 | |||
92 | $chart3 = new Chart( |
||
93 | 'chart3', // name |
||
94 | $title, // title |
||
95 | $legend, // legend |
||
96 | $plotArea, // plotArea |
||
97 | true, // plotVisibleOnly |
||
98 | '0', // displayBlanksAs, PHPExcel default |
||
99 | null, // xAxisLabel |
||
100 | $yAxisLabel // yAxisLabel |
||
101 | ); |
||
102 | self::assertSame(DataSeries::EMPTY_AS_GAP, $chart3->getDisplayBlanksAs(), 'invalid setting converted to default'); |
||
103 | |||
104 | $spreadsheet->disconnectWorksheets(); |
||
105 | } |
||
107 |