Test Failed
Push — develop ( 90366f...812a46 )
by Adrien
28:16
created

Chart::chartDataSeriesValues()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 34
Code Lines 24

Duplication

Lines 20
Ratio 58.82 %

Code Coverage

Tests 21
CRAP Score 7.0046

Importance

Changes 0
Metric Value
cc 7
eloc 24
nc 7
nop 2
dl 20
loc 34
ccs 21
cts 22
cp 0.9545
crap 7.0046
rs 6.7272
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
6
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
7
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
8
use PhpOffice\PhpSpreadsheet\Chart\Layout;
9
use PhpOffice\PhpSpreadsheet\Chart\Legend;
10
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
11
use PhpOffice\PhpSpreadsheet\Chart\Title;
12
use PhpOffice\PhpSpreadsheet\RichText\RichText;
13
use PhpOffice\PhpSpreadsheet\Style\Color;
14
use PhpOffice\PhpSpreadsheet\Style\Font;
15
use SimpleXMLElement;
16
17
class Chart
18
{
19
    /**
20
     * @param SimpleXMLElement $component
21
     * @param string $name
22
     * @param string $format
23
     */
24 2
    private static function getAttribute(SimpleXMLElement $component, $name, $format)
25
    {
26 2
        $attributes = $component->attributes();
27 2
        if (isset($attributes[$name])) {
28 2
            if ($format == 'string') {
29 2
                return (string) $attributes[$name];
30 2
            } elseif ($format == 'integer') {
31 2
                return (int) $attributes[$name];
32 2
            } elseif ($format == 'boolean') {
33 2
                return (bool) ($attributes[$name] === '0' || $attributes[$name] !== 'true') ? false : true;
34
            }
35
36
            return (float) $attributes[$name];
37
        }
38
39 2
        return null;
40
    }
41
42
    private static function readColor($color, $background = false)
43
    {
44
        if (isset($color['rgb'])) {
45
            return (string) $color['rgb'];
46
        } elseif (isset($color['indexed'])) {
47
            return Color::indexedColor($color['indexed'] - 7, $background)->getARGB();
48
        }
49
    }
50
51
    /**
52
     * @param SimpleXMLElement $chartElements
53
     * @param string $chartName
54
     */
55 2
    public static function readChart(SimpleXMLElement $chartElements, $chartName)
56
    {
57 2
        $namespacesChartMeta = $chartElements->getNamespaces(true);
58 2
        $chartElementsC = $chartElements->children($namespacesChartMeta['c']);
59
60 2
        $XaxisLabel = $YaxisLabel = $legend = $title = null;
61 2
        $dispBlanksAs = $plotVisOnly = null;
62
63 2
        foreach ($chartElementsC as $chartElementKey => $chartElement) {
64
            switch ($chartElementKey) {
65 2
                case 'chart':
66 2
                    foreach ($chartElement as $chartDetailsKey => $chartDetails) {
67 2
                        $chartDetailsC = $chartDetails->children($namespacesChartMeta['c']);
0 ignored issues
show
Unused Code introduced by
The assignment to $chartDetailsC is dead and can be removed.
Loading history...
68
                        switch ($chartDetailsKey) {
69 2
                            case 'plotArea':
70 2
                                $plotAreaLayout = $XaxisLable = $YaxisLable = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $YaxisLable is dead and can be removed.
Loading history...
Unused Code introduced by
The assignment to $XaxisLable is dead and can be removed.
Loading history...
71 2
                                $plotSeries = $plotAttributes = [];
72 2
                                foreach ($chartDetails as $chartDetailKey => $chartDetail) {
73
                                    switch ($chartDetailKey) {
74 2
                                        case 'layout':
75 2
                                            $plotAreaLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta);
76
77 2
                                            break;
78 2 View Code Duplication
                                        case 'catAx':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79 2
                                            if (isset($chartDetail->title)) {
80 2
                                                $XaxisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta['c']), $namespacesChartMeta);
81
                                            }
82
83 2
                                            break;
84 2 View Code Duplication
                                        case 'dateAx':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
                                            if (isset($chartDetail->title)) {
86
                                                $XaxisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta['c']), $namespacesChartMeta);
87
                                            }
88
89
                                            break;
90 2 View Code Duplication
                                        case 'valAx':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91 2
                                            if (isset($chartDetail->title)) {
92 2
                                                $YaxisLabel = self::chartTitle($chartDetail->title->children($namespacesChartMeta['c']), $namespacesChartMeta);
93
                                            }
94
95 2
                                            break;
96 2
                                        case 'barChart':
97 2
                                        case 'bar3DChart':
98 2
                                            $barDirection = self::getAttribute($chartDetail->barDir, 'val', 'string');
99 2
                                            $plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
100 2
                                            $plotSer->setPlotDirection($barDirection);
101 2
                                            $plotSeries[] = $plotSer;
102 2
                                            $plotAttributes = self::readChartAttributes($chartDetail);
103
104 2
                                            break;
105 2
                                        case 'lineChart':
106 2 View Code Duplication
                                        case 'line3DChart':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107 2
                                            $plotSeries[] = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
108 2
                                            $plotAttributes = self::readChartAttributes($chartDetail);
109
110 2
                                            break;
111 2
                                        case 'areaChart':
112 2 View Code Duplication
                                        case 'area3DChart':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113 2
                                            $plotSeries[] = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
114 2
                                            $plotAttributes = self::readChartAttributes($chartDetail);
115
116 2
                                            break;
117 2
                                        case 'doughnutChart':
118 2
                                        case 'pieChart':
119 2
                                        case 'pie3DChart':
120 2
                                            $explosion = isset($chartDetail->ser->explosion);
121 2
                                            $plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
122 2
                                            $plotSer->setPlotStyle($explosion);
123 2
                                            $plotSeries[] = $plotSer;
124 2
                                            $plotAttributes = self::readChartAttributes($chartDetail);
125
126 2
                                            break;
127 2 View Code Duplication
                                        case 'scatterChart':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128 2
                                            $scatterStyle = self::getAttribute($chartDetail->scatterStyle, 'val', 'string');
129 2
                                            $plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
130 2
                                            $plotSer->setPlotStyle($scatterStyle);
131 2
                                            $plotSeries[] = $plotSer;
132 2
                                            $plotAttributes = self::readChartAttributes($chartDetail);
133
134 2
                                            break;
135 2
                                        case 'bubbleChart':
136 2
                                            $bubbleScale = self::getAttribute($chartDetail->bubbleScale, 'val', 'integer');
137 2
                                            $plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
138 2
                                            $plotSer->setPlotStyle($bubbleScale);
139 2
                                            $plotSeries[] = $plotSer;
140 2
                                            $plotAttributes = self::readChartAttributes($chartDetail);
141
142 2
                                            break;
143 2 View Code Duplication
                                        case 'radarChart':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
144 2
                                            $radarStyle = self::getAttribute($chartDetail->radarStyle, 'val', 'string');
145 2
                                            $plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
146 2
                                            $plotSer->setPlotStyle($radarStyle);
147 2
                                            $plotSeries[] = $plotSer;
148 2
                                            $plotAttributes = self::readChartAttributes($chartDetail);
149
150 2
                                            break;
151 2
                                        case 'surfaceChart':
152 2
                                        case 'surface3DChart':
153 2
                                            $wireFrame = self::getAttribute($chartDetail->wireframe, 'val', 'boolean');
154 2
                                            $plotSer = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
155 2
                                            $plotSer->setPlotStyle($wireFrame);
156 2
                                            $plotSeries[] = $plotSer;
157 2
                                            $plotAttributes = self::readChartAttributes($chartDetail);
158
159 2
                                            break;
160 2 View Code Duplication
                                        case 'stockChart':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
161 2
                                            $plotSeries[] = self::chartDataSeries($chartDetail, $namespacesChartMeta, $chartDetailKey);
162 2
                                            $plotAttributes = self::readChartAttributes($plotAreaLayout);
163
164 2
                                            break;
165
                                    }
166
                                }
167 2
                                if ($plotAreaLayout == null) {
168 2
                                    $plotAreaLayout = new Layout();
169
                                }
170 2
                                $plotArea = new PlotArea($plotAreaLayout, $plotSeries);
171 2
                                self::setChartAttributes($plotAreaLayout, $plotAttributes);
172
173 2
                                break;
174 2
                            case 'plotVisOnly':
175 2
                                $plotVisOnly = self::getAttribute($chartDetails, 'val', 'string');
176
177 2
                                break;
178 2
                            case 'dispBlanksAs':
179 2
                                $dispBlanksAs = self::getAttribute($chartDetails, 'val', 'string');
180
181 2
                                break;
182 2
                            case 'title':
183 2
                                $title = self::chartTitle($chartDetails, $namespacesChartMeta);
184
185 2
                                break;
186 2
                            case 'legend':
187 2
                                $legendPos = 'r';
188 2
                                $legendLayout = null;
189 2
                                $legendOverlay = false;
190 2
                                foreach ($chartDetails as $chartDetailKey => $chartDetail) {
191
                                    switch ($chartDetailKey) {
192 2
                                        case 'legendPos':
193 2
                                            $legendPos = self::getAttribute($chartDetail, 'val', 'string');
194
195 2
                                            break;
196 2
                                        case 'overlay':
197 2
                                            $legendOverlay = self::getAttribute($chartDetail, 'val', 'boolean');
198
199 2
                                            break;
200 2
                                        case 'layout':
201 2
                                            $legendLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta);
202
203 2
                                            break;
204
                                    }
205
                                }
206 2
                                $legend = new Legend($legendPos, $legendLayout, $legendOverlay);
207
208 2
                                break;
209
                        }
210
                    }
211
            }
212
        }
213 2
        $chart = new \PhpOffice\PhpSpreadsheet\Chart\Chart($chartName, $title, $legend, $plotArea, $plotVisOnly, $dispBlanksAs, $XaxisLabel, $YaxisLabel);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $plotArea does not seem to be defined for all execution paths leading up to this point.
Loading history...
214
215 2
        return $chart;
216
    }
217
218 2
    private static function chartTitle(SimpleXMLElement $titleDetails, array $namespacesChartMeta)
219
    {
220 2
        $caption = [];
221 2
        $titleLayout = null;
222 2
        foreach ($titleDetails as $titleDetailKey => $chartDetail) {
223
            switch ($titleDetailKey) {
224 2
                case 'tx':
225 2
                    $titleDetails = $chartDetail->rich->children($namespacesChartMeta['a']);
226 2
                    foreach ($titleDetails as $titleKey => $titleDetail) {
227
                        switch ($titleKey) {
228 2
                            case 'p':
229 2
                                $titleDetailPart = $titleDetail->children($namespacesChartMeta['a']);
230 2
                                $caption[] = self::parseRichText($titleDetailPart);
231
                        }
232
                    }
233
234 2
                    break;
235 2
                case 'layout':
236 2
                    $titleLayout = self::chartLayoutDetails($chartDetail, $namespacesChartMeta);
237
238 2
                    break;
239
            }
240
        }
241
242 2
        return new Title($caption, $titleLayout);
243
    }
244
245 2
    private static function chartLayoutDetails($chartDetail, $namespacesChartMeta)
246
    {
247 2
        if (!isset($chartDetail->manualLayout)) {
248 2
            return null;
249
        }
250 2
        $details = $chartDetail->manualLayout->children($namespacesChartMeta['c']);
251 2
        if ($details === null) {
252
            return null;
253
        }
254 2
        $layout = [];
255 2
        foreach ($details as $detailKey => $detail) {
256 2
            $layout[$detailKey] = self::getAttribute($detail, 'val', 'string');
257
        }
258
259 2
        return new Layout($layout);
260
    }
261
262 2
    private static function chartDataSeries($chartDetail, $namespacesChartMeta, $plotType)
263
    {
264 2
        $multiSeriesType = null;
265 2
        $smoothLine = false;
266 2
        $seriesLabel = $seriesCategory = $seriesValues = $plotOrder = [];
267
268 2
        $seriesDetailSet = $chartDetail->children($namespacesChartMeta['c']);
269 2
        foreach ($seriesDetailSet as $seriesDetailKey => $seriesDetails) {
270
            switch ($seriesDetailKey) {
271 2
                case 'grouping':
272 2
                    $multiSeriesType = self::getAttribute($chartDetail->grouping, 'val', 'string');
273
274 2
                    break;
275 2
                case 'ser':
276 2
                    $marker = null;
277 2
                    foreach ($seriesDetails as $seriesKey => $seriesDetail) {
278
                        switch ($seriesKey) {
279 2
                            case 'idx':
280 2
                                $seriesIndex = self::getAttribute($seriesDetail, 'val', 'integer');
281
282 2
                                break;
283 2
                            case 'order':
284 2
                                $seriesOrder = self::getAttribute($seriesDetail, 'val', 'integer');
285 2
                                $plotOrder[$seriesIndex] = $seriesOrder;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $seriesIndex does not seem to be defined for all execution paths leading up to this point.
Loading history...
286
287 2
                                break;
288 2
                            case 'tx':
289 2
                                $seriesLabel[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta);
290
291 2
                                break;
292 2
                            case 'marker':
293 2
                                $marker = self::getAttribute($seriesDetail->symbol, 'val', 'string');
294
295 2
                                break;
296 2
                            case 'smooth':
297 2
                                $smoothLine = self::getAttribute($seriesDetail, 'val', 'boolean');
298
299 2
                                break;
300 2
                            case 'cat':
301 2
                                $seriesCategory[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta);
302
303 2
                                break;
304 2
                            case 'val':
305 2
                                $seriesValues[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker);
306
307 2
                                break;
308 2
                            case 'xVal':
309 2
                                $seriesCategory[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker);
310
311 2
                                break;
312 2
                            case 'yVal':
313 2
                                $seriesValues[$seriesIndex] = self::chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker);
314
315 2
                                break;
316
                        }
317
                    }
318
            }
319
        }
320
321 2
        return new DataSeries($plotType, $multiSeriesType, $plotOrder, $seriesLabel, $seriesCategory, $seriesValues, $smoothLine);
322
    }
323
324 2
    private static function chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker = null)
325
    {
326 2
        if (isset($seriesDetail->strRef)) {
327 2
            $seriesSource = (string) $seriesDetail->strRef->f;
328 2
            $seriesData = self::chartDataSeriesValues($seriesDetail->strRef->strCache->children($namespacesChartMeta['c']), 's');
329
330 2
            return new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker);
331 2
        } elseif (isset($seriesDetail->numRef)) {
332 2
            $seriesSource = (string) $seriesDetail->numRef->f;
333 2
            $seriesData = self::chartDataSeriesValues($seriesDetail->numRef->numCache->children($namespacesChartMeta['c']));
334
335 2
            return new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker);
336 2
        } elseif (isset($seriesDetail->multiLvlStrRef)) {
337 2
            $seriesSource = (string) $seriesDetail->multiLvlStrRef->f;
338 2
            $seriesData = self::chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlStrRef->multiLvlStrCache->children($namespacesChartMeta['c']), 's');
339 2
            $seriesData['pointCount'] = count($seriesData['dataValues']);
340
341 2
            return new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker);
342
        } elseif (isset($seriesDetail->multiLvlNumRef)) {
343
            $seriesSource = (string) $seriesDetail->multiLvlNumRef->f;
344
            $seriesData = self::chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlNumRef->multiLvlNumCache->children($namespacesChartMeta['c']), 's');
345
            $seriesData['pointCount'] = count($seriesData['dataValues']);
346
347
            return new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, $seriesSource, $seriesData['formatCode'], $seriesData['pointCount'], $seriesData['dataValues'], $marker);
348
        }
349
350
        return null;
351
    }
352
353 2
    private static function chartDataSeriesValues($seriesValueSet, $dataType = 'n')
354
    {
355 2
        $seriesVal = [];
356 2
        $formatCode = '';
357 2
        $pointCount = 0;
358
359 2 View Code Duplication
        foreach ($seriesValueSet as $seriesValueIdx => $seriesValue) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
360
            switch ($seriesValueIdx) {
361 2
                case 'ptCount':
362 2
                    $pointCount = self::getAttribute($seriesValue, 'val', 'integer');
363
364 2
                    break;
365 2
                case 'formatCode':
366 2
                    $formatCode = (string) $seriesValue;
367
368 2
                    break;
369 2
                case 'pt':
370 2
                    $pointVal = self::getAttribute($seriesValue, 'idx', 'integer');
371 2
                    if ($dataType == 's') {
372 2
                        $seriesVal[$pointVal] = (string) $seriesValue->v;
373 2
                    } elseif ($seriesValue->v === Functions::NA()) {
374
                        $seriesVal[$pointVal] = null;
375
                    } else {
376 2
                        $seriesVal[$pointVal] = (float) $seriesValue->v;
377
                    }
378
379 2
                    break;
380
            }
381
        }
382
383
        return [
384 2
            'formatCode' => $formatCode,
385 2
            'pointCount' => $pointCount,
386 2
            'dataValues' => $seriesVal,
387
        ];
388
    }
389
390 2
    private static function chartDataSeriesValuesMultiLevel($seriesValueSet, $dataType = 'n')
391
    {
392 2
        $seriesVal = [];
393 2
        $formatCode = '';
394 2
        $pointCount = 0;
395
396 2
        foreach ($seriesValueSet->lvl as $seriesLevelIdx => $seriesLevel) {
397 2 View Code Duplication
            foreach ($seriesLevel as $seriesValueIdx => $seriesValue) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
398
                switch ($seriesValueIdx) {
399 2
                    case 'ptCount':
400
                        $pointCount = self::getAttribute($seriesValue, 'val', 'integer');
401
402
                        break;
403 2
                    case 'formatCode':
404
                        $formatCode = (string) $seriesValue;
405
406
                        break;
407 2
                    case 'pt':
408 2
                        $pointVal = self::getAttribute($seriesValue, 'idx', 'integer');
409 2
                        if ($dataType == 's') {
410 2
                            $seriesVal[$pointVal][] = (string) $seriesValue->v;
411
                        } elseif ($seriesValue->v === Functions::NA()) {
412
                            $seriesVal[$pointVal] = null;
413
                        } else {
414
                            $seriesVal[$pointVal][] = (float) $seriesValue->v;
415
                        }
416
417 2
                        break;
418
                }
419
            }
420
        }
421
422
        return [
423 2
            'formatCode' => $formatCode,
424 2
            'pointCount' => $pointCount,
425 2
            'dataValues' => $seriesVal,
426
        ];
427
    }
428
429 2
    private static function parseRichText(SimpleXMLElement $titleDetailPart)
430
    {
431 2
        $value = new RichText();
432
433 2
        foreach ($titleDetailPart as $titleDetailElementKey => $titleDetailElement) {
434 2
            if (isset($titleDetailElement->t)) {
435 2
                $objText = $value->createTextRun((string) $titleDetailElement->t);
436
            }
437 2
            if (isset($titleDetailElement->rPr)) {
438 2 View Code Duplication
                if (isset($titleDetailElement->rPr->rFont['val'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
439
                    $objText->getFont()->setName((string) $titleDetailElement->rPr->rFont['val']);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $objText does not seem to be defined for all execution paths leading up to this point.
Loading history...
440
                }
441
442 2
                $fontSize = (self::getAttribute($titleDetailElement->rPr, 'sz', 'integer'));
443 2
                if ($fontSize !== null) {
444 2
                    $objText->getFont()->setSize(floor($fontSize / 100));
445
                }
446
447 2
                $fontColor = (self::getAttribute($titleDetailElement->rPr, 'color', 'string'));
448 2
                if ($fontColor !== null) {
449
                    $objText->getFont()->setColor(new Color(self::readColor($fontColor)));
450
                }
451
452 2
                $bold = self::getAttribute($titleDetailElement->rPr, 'b', 'boolean');
453 2
                if ($bold !== null) {
454 2
                    $objText->getFont()->setBold($bold);
455
                }
456
457 2
                $italic = self::getAttribute($titleDetailElement->rPr, 'i', 'boolean');
458 2
                if ($italic !== null) {
459 2
                    $objText->getFont()->setItalic($italic);
460
                }
461
462 2
                $baseline = self::getAttribute($titleDetailElement->rPr, 'baseline', 'integer');
463 2
                if ($baseline !== null) {
464 2
                    if ($baseline > 0) {
465 2
                        $objText->getFont()->setSuperscript(true);
466 2
                    } elseif ($baseline < 0) {
467 2
                        $objText->getFont()->setSubscript(true);
468
                    }
469
                }
470
471 2
                $underscore = (self::getAttribute($titleDetailElement->rPr, 'u', 'string'));
472 2
                if ($underscore !== null) {
473 2
                    if ($underscore == 'sng') {
474 2
                        $objText->getFont()->setUnderline(Font::UNDERLINE_SINGLE);
475 2
                    } elseif ($underscore == 'dbl') {
476 2
                        $objText->getFont()->setUnderline(Font::UNDERLINE_DOUBLE);
477
                    } else {
478 2
                        $objText->getFont()->setUnderline(Font::UNDERLINE_NONE);
479
                    }
480
                }
481
482 2
                $strikethrough = (self::getAttribute($titleDetailElement->rPr, 's', 'string'));
483 2
                if ($strikethrough !== null) {
484
                    if ($strikethrough == 'noStrike') {
485
                        $objText->getFont()->setStrikethrough(false);
486
                    } else {
487 2
                        $objText->getFont()->setStrikethrough(true);
488
                    }
489
                }
490
            }
491
        }
492
493 2
        return $value;
494
    }
495
496 2
    private static function readChartAttributes($chartDetail)
497
    {
498 2
        $plotAttributes = [];
499 2
        if (isset($chartDetail->dLbls)) {
500 2
            if (isset($chartDetail->dLbls->howLegendKey)) {
501
                $plotAttributes['showLegendKey'] = self::getAttribute($chartDetail->dLbls->showLegendKey, 'val', 'string');
502
            }
503 2 View Code Duplication
            if (isset($chartDetail->dLbls->showVal)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
504 2
                $plotAttributes['showVal'] = self::getAttribute($chartDetail->dLbls->showVal, 'val', 'string');
505
            }
506 2 View Code Duplication
            if (isset($chartDetail->dLbls->showCatName)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
507 2
                $plotAttributes['showCatName'] = self::getAttribute($chartDetail->dLbls->showCatName, 'val', 'string');
508
            }
509 2 View Code Duplication
            if (isset($chartDetail->dLbls->showSerName)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
510 2
                $plotAttributes['showSerName'] = self::getAttribute($chartDetail->dLbls->showSerName, 'val', 'string');
511
            }
512 2 View Code Duplication
            if (isset($chartDetail->dLbls->showPercent)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
513 2
                $plotAttributes['showPercent'] = self::getAttribute($chartDetail->dLbls->showPercent, 'val', 'string');
514
            }
515 2 View Code Duplication
            if (isset($chartDetail->dLbls->showBubbleSize)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
516 2
                $plotAttributes['showBubbleSize'] = self::getAttribute($chartDetail->dLbls->showBubbleSize, 'val', 'string');
517
            }
518 2 View Code Duplication
            if (isset($chartDetail->dLbls->showLeaderLines)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
519 2
                $plotAttributes['showLeaderLines'] = self::getAttribute($chartDetail->dLbls->showLeaderLines, 'val', 'string');
520
            }
521
        }
522
523 2
        return $plotAttributes;
524
    }
525
526
    /**
527
     * @param Layout $plotArea
528
     * @param mixed $plotAttributes
529
     */
530 2
    private static function setChartAttributes(Layout $plotArea, $plotAttributes)
531
    {
532 2
        foreach ($plotAttributes as $plotAttributeKey => $plotAttributeValue) {
533
            switch ($plotAttributeKey) {
534 2
                case 'showLegendKey':
535
                    $plotArea->setShowLegendKey($plotAttributeValue);
536
537
                    break;
538 2
                case 'showVal':
539 2
                    $plotArea->setShowVal($plotAttributeValue);
540
541 2
                    break;
542 2
                case 'showCatName':
543 2
                    $plotArea->setShowCatName($plotAttributeValue);
544
545 2
                    break;
546 2
                case 'showSerName':
547 2
                    $plotArea->setShowSerName($plotAttributeValue);
548
549 2
                    break;
550 2
                case 'showPercent':
551 2
                    $plotArea->setShowPercent($plotAttributeValue);
552
553 2
                    break;
554 2
                case 'showBubbleSize':
555 2
                    $plotArea->setShowBubbleSize($plotAttributeValue);
556
557 2
                    break;
558 2
                case 'showLeaderLines':
559 2
                    $plotArea->setShowLeaderLines($plotAttributeValue);
560
561 2
                    break;
562
            }
563
        }
564 2
    }
565
}
566