Completed
Push — develop ( 41a1aa...ec7312 )
by Adrien
26:57
created

Chart::writePlotArea()   F

Complexity

Conditions 22
Paths 274

Size

Total Lines 122
Code Lines 85

Duplication

Lines 20
Ratio 16.39 %

Code Coverage

Tests 83
CRAP Score 22.0008

Importance

Changes 0
Metric Value
cc 22
eloc 85
nc 274
nop 9
dl 20
loc 122
ccs 83
cts 84
cp 0.9881
crap 22.0008
rs 3.5977
c 0
b 0
f 0

How to fix   Long Method    Complexity    Many Parameters   

Long Method

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:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;
4
5
use PhpOffice\PhpSpreadsheet\Chart\Axis;
6
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
7
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
8
use PhpOffice\PhpSpreadsheet\Chart\GridLines;
9
use PhpOffice\PhpSpreadsheet\Chart\Layout;
10
use PhpOffice\PhpSpreadsheet\Chart\Legend;
11
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
12
use PhpOffice\PhpSpreadsheet\Chart\Title;
13
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
14
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
15
use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException;
16
17
/**
18
 * Copyright (c) 2006 - 2016 PhpSpreadsheet.
19
 *
20
 * This library is free software; you can redistribute it and/or
21
 * modify it under the terms of the GNU Lesser General Public
22
 * License as published by the Free Software Foundation; either
23
 * version 2.1 of the License, or (at your option) any later version.
24
 *
25
 * This library is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
 * Lesser General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU Lesser General Public
31
 * License along with this library; if not, write to the Free Software
32
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33
 *
34
 * @category   PhpSpreadsheet
35
 *
36
 * @copyright  Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
37
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
38
 */
39
class Chart extends WriterPart
40
{
41
    protected $calculateCellValues;
42
43
    /**
44
     * Write charts to XML format.
45
     *
46
     * @param \PhpOffice\PhpSpreadsheet\Chart $pChart
47
     * @param mixed $calculateCellValues
48
     *
49
     * @throws WriterException
50
     *
51
     * @return string XML Output
52
     */
53 13
    public function writeChart(\PhpOffice\PhpSpreadsheet\Chart $pChart, $calculateCellValues = true)
54
    {
55 13
        $this->calculateCellValues = $calculateCellValues;
56
57
        // Create XML writer
58 13
        $objWriter = null;
0 ignored issues
show
Unused Code introduced by
$objWriter is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
59 13 View Code Duplication
        if ($this->getParentWriter()->getUseDiskCaching()) {
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...
60
            $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
61
        } else {
62 13
            $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
63
        }
64
        //    Ensure that data series values are up-to-date before we save
65 13
        if ($this->calculateCellValues) {
66 13
            $pChart->refresh();
67
        }
68
69
        // XML header
70 13
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');
71
72
        // c:chartSpace
73 13
        $objWriter->startElement('c:chartSpace');
74 13
        $objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
75 13
        $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
76 13
        $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
77
78 13
        $objWriter->startElement('c:date1904');
79 13
        $objWriter->writeAttribute('val', 0);
80 13
        $objWriter->endElement();
81 13
        $objWriter->startElement('c:lang');
82 13
        $objWriter->writeAttribute('val', 'en-GB');
83 13
        $objWriter->endElement();
84 13
        $objWriter->startElement('c:roundedCorners');
85 13
        $objWriter->writeAttribute('val', 0);
86 13
        $objWriter->endElement();
87
88 13
        $this->writeAlternateContent($objWriter);
89
90 13
        $objWriter->startElement('c:chart');
91
92 13
        $this->writeTitle($objWriter, $pChart->getTitle());
93
94 13
        $objWriter->startElement('c:autoTitleDeleted');
95 13
        $objWriter->writeAttribute('val', 0);
96 13
        $objWriter->endElement();
97
98 13
        $this->writePlotArea($objWriter, $pChart->getWorksheet(), $pChart->getPlotArea(), $pChart->getXAxisLabel(), $pChart->getYAxisLabel(), $pChart->getChartAxisX(), $pChart->getChartAxisY(), $pChart->getMajorGridlines(), $pChart->getMinorGridlines());
99
100 13
        $this->writeLegend($objWriter, $pChart->getLegend());
101
102 13
        $objWriter->startElement('c:plotVisOnly');
103 13
        $objWriter->writeAttribute('val', 1);
104 13
        $objWriter->endElement();
105
106 13
        $objWriter->startElement('c:dispBlanksAs');
107 13
        $objWriter->writeAttribute('val', 'gap');
108 13
        $objWriter->endElement();
109
110 13
        $objWriter->startElement('c:showDLblsOverMax');
111 13
        $objWriter->writeAttribute('val', 0);
112 13
        $objWriter->endElement();
113
114 13
        $objWriter->endElement();
115
116 13
        $this->writePrintSettings($objWriter);
117
118 13
        $objWriter->endElement();
119
120
        // Return
121 13
        return $objWriter->getData();
122
    }
123
124
    /**
125
     * Write Chart Title.
126
     *
127
     * @param XMLWriter $objWriter XML Writer
128
     * @param Title $title
129
     *
130
     * @throws WriterException
131
     */
132 13
    private function writeTitle(XMLWriter $objWriter, Title $title = null)
133
    {
134 13
        if (is_null($title)) {
135 1
            return;
136
        }
137
138 13
        $objWriter->startElement('c:title');
139 13
        $objWriter->startElement('c:tx');
140 13
        $objWriter->startElement('c:rich');
141
142 13
        $objWriter->startElement('a:bodyPr');
143 13
        $objWriter->endElement();
144
145 13
        $objWriter->startElement('a:lstStyle');
146 13
        $objWriter->endElement();
147
148 13
        $objWriter->startElement('a:p');
149
150 13
        $caption = $title->getCaption();
151 13
        if ((is_array($caption)) && (count($caption) > 0)) {
152 1
            $caption = $caption[0];
153
        }
154 13
        $this->getParentWriter()->getWriterPart('stringtable')->writeRichTextForCharts($objWriter, $caption, 'a');
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart as the method writeRichTextForCharts() does only exist in the following sub-classes of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart: PhpOffice\PhpSpreadsheet\Writer\Xlsx\StringTable. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
155
156 13
        $objWriter->endElement();
157 13
        $objWriter->endElement();
158 13
        $objWriter->endElement();
159
160 13
        $this->writeLayout($objWriter, $title->getLayout());
161
162 13
        $objWriter->startElement('c:overlay');
163 13
        $objWriter->writeAttribute('val', 0);
164 13
        $objWriter->endElement();
165
166 13
        $objWriter->endElement();
167 13
    }
168
169
    /**
170
     * Write Chart Legend.
171
     *
172
     * @param XMLWriter $objWriter XML Writer
173
     * @param Legend $legend
174
     *
175
     * @throws WriterException
176
     */
177 13
    private function writeLegend(XMLWriter $objWriter, Legend $legend = null)
178
    {
179 13
        if (is_null($legend)) {
180 2
            return;
181
        }
182
183 13
        $objWriter->startElement('c:legend');
184
185 13
        $objWriter->startElement('c:legendPos');
186 13
        $objWriter->writeAttribute('val', $legend->getPosition());
187 13
        $objWriter->endElement();
188
189 13
        $this->writeLayout($objWriter, $legend->getLayout());
190
191 13
        $objWriter->startElement('c:overlay');
192 13
        $objWriter->writeAttribute('val', ($legend->getOverlay()) ? '1' : '0');
193 13
        $objWriter->endElement();
194
195 13
        $objWriter->startElement('c:txPr');
196 13
        $objWriter->startElement('a:bodyPr');
197 13
        $objWriter->endElement();
198
199 13
        $objWriter->startElement('a:lstStyle');
200 13
        $objWriter->endElement();
201
202 13
        $objWriter->startElement('a:p');
203 13
        $objWriter->startElement('a:pPr');
204 13
        $objWriter->writeAttribute('rtl', 0);
205
206 13
        $objWriter->startElement('a:defRPr');
207 13
        $objWriter->endElement();
208 13
        $objWriter->endElement();
209
210 13
        $objWriter->startElement('a:endParaRPr');
211 13
        $objWriter->writeAttribute('lang', 'en-US');
212 13
        $objWriter->endElement();
213
214 13
        $objWriter->endElement();
215 13
        $objWriter->endElement();
216
217 13
        $objWriter->endElement();
218 13
    }
219
220
    /**
221
     * Write Chart Plot Area.
222
     *
223
     * @param XMLWriter $objWriter XML Writer
224
     * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet
225
     * @param PlotArea $plotArea
226
     * @param Title $xAxisLabel
227
     * @param Title $yAxisLabel
228
     * @param Axis $xAxis
229
     * @param Axis $yAxis
230
     *
231
     * @throws WriterException
232
     */
233 13
    private function writePlotArea(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet, PlotArea $plotArea, Title $xAxisLabel = null, Title $yAxisLabel = null, Axis $xAxis = null, Axis $yAxis = null, GridLines $majorGridlines = null, GridLines $minorGridlines = null)
234
    {
235 13
        if (is_null($plotArea)) {
236
            return;
237
        }
238
239 13
        $id1 = $id2 = 0;
240 13
        $this->_seriesIndex = 0;
0 ignored issues
show
Bug introduced by
The property _seriesIndex does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
241 13
        $objWriter->startElement('c:plotArea');
242
243 13
        $layout = $plotArea->getLayout();
244
245 13
        $this->writeLayout($objWriter, $layout);
246
247 13
        $chartTypes = self::getChartType($plotArea);
248 13
        $catIsMultiLevelSeries = $valIsMultiLevelSeries = false;
249 13
        $plotGroupingType = '';
250 13
        foreach ($chartTypes as $chartType) {
0 ignored issues
show
Bug introduced by
The expression $chartTypes of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
251 13
            $objWriter->startElement('c:' . $chartType);
252
253 13
            $groupCount = $plotArea->getPlotGroupCount();
254 13
            for ($i = 0; $i < $groupCount; ++$i) {
255 13
                $plotGroup = $plotArea->getPlotGroupByIndex($i);
256 13
                $groupType = $plotGroup->getPlotType();
257 13
                if ($groupType == $chartType) {
258 13
                    $plotStyle = $plotGroup->getPlotStyle();
259 13
                    if ($groupType === DataSeries::TYPE_RADARCHART) {
260 2
                        $objWriter->startElement('c:radarStyle');
261 2
                        $objWriter->writeAttribute('val', $plotStyle);
262 2
                        $objWriter->endElement();
263 12
                    } elseif ($groupType === DataSeries::TYPE_SCATTERCHART) {
264 2
                        $objWriter->startElement('c:scatterStyle');
265 2
                        $objWriter->writeAttribute('val', $plotStyle);
266 2
                        $objWriter->endElement();
267
                    }
268
269 13
                    $this->writePlotGroup($plotGroup, $chartType, $objWriter, $catIsMultiLevelSeries, $valIsMultiLevelSeries, $plotGroupingType, $pSheet);
270
                }
271
            }
272
273 13
            $this->writeDataLabels($objWriter, $layout);
274
275 13
            if ($chartType === DataSeries::TYPE_LINECHART) {
276
                //    Line only, Line3D can't be smoothed
277 3
                $objWriter->startElement('c:smooth');
278 3
                $objWriter->writeAttribute('val', (int) $plotGroup->getSmoothLine());
0 ignored issues
show
Bug introduced by
The variable $plotGroup does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
279 3
                $objWriter->endElement();
280 12
            } elseif (($chartType === DataSeries::TYPE_BARCHART) || ($chartType === DataSeries::TYPE_BARCHART_3D)) {
281 7
                $objWriter->startElement('c:gapWidth');
282 7
                $objWriter->writeAttribute('val', 150);
283 7
                $objWriter->endElement();
284
285 7
                if ($plotGroupingType == 'percentStacked' || $plotGroupingType == 'stacked') {
286 2
                    $objWriter->startElement('c:overlap');
287 2
                    $objWriter->writeAttribute('val', 100);
288 7
                    $objWriter->endElement();
289
                }
290 8 View Code Duplication
            } elseif ($chartType === DataSeries::TYPE_BUBBLECHART) {
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...
291 1
                $objWriter->startElement('c:bubbleScale');
292 1
                $objWriter->writeAttribute('val', 25);
293 1
                $objWriter->endElement();
294
295 1
                $objWriter->startElement('c:showNegBubbles');
296 1
                $objWriter->writeAttribute('val', 0);
297 1
                $objWriter->endElement();
298 8
            } elseif ($chartType === DataSeries::TYPE_STOCKCHART) {
299 2
                $objWriter->startElement('c:hiLowLines');
300 2
                $objWriter->endElement();
301
302 2
                $objWriter->startElement('c:upDownBars');
303
304 2
                $objWriter->startElement('c:gapWidth');
305 2
                $objWriter->writeAttribute('val', 300);
306 2
                $objWriter->endElement();
307
308 2
                $objWriter->startElement('c:upBars');
309 2
                $objWriter->endElement();
310
311 2
                $objWriter->startElement('c:downBars');
312 2
                $objWriter->endElement();
313
314 2
                $objWriter->endElement();
315
            }
316
317
            //    Generate 2 unique numbers to use for axId values
318 13
            $id1 = '75091328';
319 13
            $id2 = '75089408';
320
321 13
            if (($chartType !== DataSeries::TYPE_PIECHART) && ($chartType !== DataSeries::TYPE_PIECHART_3D) && ($chartType !== DataSeries::TYPE_DONUTCHART)) {
322 12
                $objWriter->startElement('c:axId');
323 12
                $objWriter->writeAttribute('val', $id1);
324 12
                $objWriter->endElement();
325 12
                $objWriter->startElement('c:axId');
326 12
                $objWriter->writeAttribute('val', $id2);
327 12
                $objWriter->endElement();
328 View Code Duplication
            } else {
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...
329 2
                $objWriter->startElement('c:firstSliceAng');
330 2
                $objWriter->writeAttribute('val', 0);
331 2
                $objWriter->endElement();
332
333 2
                if ($chartType === DataSeries::TYPE_DONUTCHART) {
334 2
                    $objWriter->startElement('c:holeSize');
335 2
                    $objWriter->writeAttribute('val', 50);
336 2
                    $objWriter->endElement();
337
                }
338
            }
339
340 13
            $objWriter->endElement();
341
        }
342
343 13
        if (($chartType !== DataSeries::TYPE_PIECHART) && ($chartType !== DataSeries::TYPE_PIECHART_3D) && ($chartType !== DataSeries::TYPE_DONUTCHART)) {
344 12
            if ($chartType === DataSeries::TYPE_BUBBLECHART) {
345 1
                $this->writeValueAxis($objWriter, $plotArea, $xAxisLabel, $chartType, $id1, $id2, $catIsMultiLevelSeries, $xAxis, $yAxis, $majorGridlines, $minorGridlines);
0 ignored issues
show
Bug introduced by
The variable $chartType seems to be defined by a foreach iteration on line 250. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
Bug introduced by
It seems like $xAxisLabel defined by parameter $xAxisLabel on line 233 can be null; however, PhpOffice\PhpSpreadsheet...Chart::writeValueAxis() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
346
            } else {
347 12
                $this->writeCategoryAxis($objWriter, $plotArea, $xAxisLabel, $chartType, $id1, $id2, $catIsMultiLevelSeries, $xAxis, $yAxis);
0 ignored issues
show
Bug introduced by
It seems like $xAxisLabel defined by parameter $xAxisLabel on line 233 can be null; however, PhpOffice\PhpSpreadsheet...rt::writeCategoryAxis() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
348
            }
349
350 12
            $this->writeValueAxis($objWriter, $plotArea, $yAxisLabel, $chartType, $id1, $id2, $valIsMultiLevelSeries, $xAxis, $yAxis, $majorGridlines, $minorGridlines);
0 ignored issues
show
Bug introduced by
It seems like $yAxisLabel defined by parameter $yAxisLabel on line 233 can be null; however, PhpOffice\PhpSpreadsheet...Chart::writeValueAxis() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
351
        }
352
353 13
        $objWriter->endElement();
354 13
    }
355
356
    /**
357
     * Write Data Labels.
358
     *
359
     * @param XMLWriter $objWriter XML Writer
360
     * @param \PhpOffice\PhpSpreadsheet\Chart\Layout $chartLayout Chart layout
361
     *
362
     * @throws WriterException
363
     */
364 13
    private function writeDataLabels(XMLWriter $objWriter, Layout $chartLayout = null)
365
    {
366 13
        $objWriter->startElement('c:dLbls');
367
368 13
        $objWriter->startElement('c:showLegendKey');
369 13
        $showLegendKey = (empty($chartLayout)) ? 0 : $chartLayout->getShowLegendKey();
370 13
        $objWriter->writeAttribute('val', ((empty($showLegendKey)) ? 0 : 1));
371 13
        $objWriter->endElement();
372
373 13
        $objWriter->startElement('c:showVal');
374 13
        $showVal = (empty($chartLayout)) ? 0 : $chartLayout->getShowVal();
375 13
        $objWriter->writeAttribute('val', ((empty($showVal)) ? 0 : 1));
376 13
        $objWriter->endElement();
377
378 13
        $objWriter->startElement('c:showCatName');
379 13
        $showCatName = (empty($chartLayout)) ? 0 : $chartLayout->getShowCatName();
380 13
        $objWriter->writeAttribute('val', ((empty($showCatName)) ? 0 : 1));
381 13
        $objWriter->endElement();
382
383 13
        $objWriter->startElement('c:showSerName');
384 13
        $showSerName = (empty($chartLayout)) ? 0 : $chartLayout->getShowSerName();
385 13
        $objWriter->writeAttribute('val', ((empty($showSerName)) ? 0 : 1));
386 13
        $objWriter->endElement();
387
388 13
        $objWriter->startElement('c:showPercent');
389 13
        $showPercent = (empty($chartLayout)) ? 0 : $chartLayout->getShowPercent();
390 13
        $objWriter->writeAttribute('val', ((empty($showPercent)) ? 0 : 1));
391 13
        $objWriter->endElement();
392
393 13
        $objWriter->startElement('c:showBubbleSize');
394 13
        $showBubbleSize = (empty($chartLayout)) ? 0 : $chartLayout->getShowBubbleSize();
395 13
        $objWriter->writeAttribute('val', ((empty($showBubbleSize)) ? 0 : 1));
396 13
        $objWriter->endElement();
397
398 13
        $objWriter->startElement('c:showLeaderLines');
399 13
        $showLeaderLines = (empty($chartLayout)) ? 1 : $chartLayout->getShowLeaderLines();
400 13
        $objWriter->writeAttribute('val', ((empty($showLeaderLines)) ? 0 : 1));
401 13
        $objWriter->endElement();
402
403 13
        $objWriter->endElement();
404 13
    }
405
406
    /**
407
     * Write Category Axis.
408
     *
409
     * @param XMLWriter $objWriter XML Writer
410
     * @param PlotArea $plotArea
411
     * @param Title $xAxisLabel
412
     * @param string $groupType Chart type
413
     * @param string $id1
414
     * @param string $id2
415
     * @param bool $isMultiLevelSeries
416
     * @param mixed $xAxis
417
     * @param mixed $yAxis
418
     *
419
     * @throws WriterException
420
     */
421 12
    private function writeCategoryAxis($objWriter, PlotArea $plotArea, $xAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries, $xAxis, $yAxis)
0 ignored issues
show
Unused Code introduced by
The parameter $plotArea is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $groupType is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $xAxis is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
422
    {
423 12
        $objWriter->startElement('c:catAx');
424
425 12
        if ($id1 > 0) {
426 12
            $objWriter->startElement('c:axId');
427 12
            $objWriter->writeAttribute('val', $id1);
428 12
            $objWriter->endElement();
429
        }
430
431 12
        $objWriter->startElement('c:scaling');
432 12
        $objWriter->startElement('c:orientation');
433 12
        $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('orientation'));
434 12
        $objWriter->endElement();
435 12
        $objWriter->endElement();
436
437 12
        $objWriter->startElement('c:delete');
438 12
        $objWriter->writeAttribute('val', 0);
439 12
        $objWriter->endElement();
440
441 12
        $objWriter->startElement('c:axPos');
442 12
        $objWriter->writeAttribute('val', 'b');
443 12
        $objWriter->endElement();
444
445 12 View Code Duplication
        if (!is_null($xAxisLabel)) {
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...
446 3
            $objWriter->startElement('c:title');
447 3
            $objWriter->startElement('c:tx');
448 3
            $objWriter->startElement('c:rich');
449
450 3
            $objWriter->startElement('a:bodyPr');
451 3
            $objWriter->endElement();
452
453 3
            $objWriter->startElement('a:lstStyle');
454 3
            $objWriter->endElement();
455
456 3
            $objWriter->startElement('a:p');
457 3
            $objWriter->startElement('a:r');
458
459 3
            $caption = $xAxisLabel->getCaption();
460 3
            if (is_array($caption)) {
461 1
                $caption = $caption[0];
462
            }
463 3
            $objWriter->startElement('a:t');
464 3
            $objWriter->writeRawData(StringHelper::controlCharacterPHP2OOXML($caption));
465 3
            $objWriter->endElement();
466
467 3
            $objWriter->endElement();
468 3
            $objWriter->endElement();
469 3
            $objWriter->endElement();
470 3
            $objWriter->endElement();
471
472 3
            $layout = $xAxisLabel->getLayout();
473 3
            $this->writeLayout($objWriter, $layout);
474
475 3
            $objWriter->startElement('c:overlay');
476 3
            $objWriter->writeAttribute('val', 0);
477 3
            $objWriter->endElement();
478
479 3
            $objWriter->endElement();
480
        }
481
482 12
        $objWriter->startElement('c:numFmt');
483 12
        $objWriter->writeAttribute('formatCode', $yAxis->getAxisNumberFormat());
484 12
        $objWriter->writeAttribute('sourceLinked', $yAxis->getAxisNumberSourceLinked());
485 12
        $objWriter->endElement();
486
487 12
        $objWriter->startElement('c:majorTickMark');
488 12
        $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('major_tick_mark'));
489 12
        $objWriter->endElement();
490
491 12
        $objWriter->startElement('c:minorTickMark');
492 12
        $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('minor_tick_mark'));
493 12
        $objWriter->endElement();
494
495 12
        $objWriter->startElement('c:tickLblPos');
496 12
        $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('axis_labels'));
497 12
        $objWriter->endElement();
498
499 12
        if ($id2 > 0) {
500 12
            $objWriter->startElement('c:crossAx');
501 12
            $objWriter->writeAttribute('val', $id2);
502 12
            $objWriter->endElement();
503
504 12
            $objWriter->startElement('c:crosses');
505 12
            $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('horizontal_crosses'));
506 12
            $objWriter->endElement();
507
        }
508
509 12
        $objWriter->startElement('c:auto');
510 12
        $objWriter->writeAttribute('val', 1);
511 12
        $objWriter->endElement();
512
513 12
        $objWriter->startElement('c:lblAlgn');
514 12
        $objWriter->writeAttribute('val', 'ctr');
515 12
        $objWriter->endElement();
516
517 12
        $objWriter->startElement('c:lblOffset');
518 12
        $objWriter->writeAttribute('val', 100);
519 12
        $objWriter->endElement();
520
521 12
        if ($isMultiLevelSeries) {
522 2
            $objWriter->startElement('c:noMultiLvlLbl');
523 2
            $objWriter->writeAttribute('val', 0);
524 2
            $objWriter->endElement();
525
        }
526 12
        $objWriter->endElement();
527 12
    }
528
529
    /**
530
     * Write Value Axis.
531
     *
532
     * @param XMLWriter $objWriter XML Writer
533
     * @param PlotArea $plotArea
534
     * @param Title $yAxisLabel
535
     * @param string $groupType Chart type
536
     * @param string $id1
537
     * @param string $id2
538
     * @param bool $isMultiLevelSeries
539
     * @param mixed $xAxis
540
     * @param mixed $yAxis
541
     * @param mixed $majorGridlines
542
     * @param mixed $minorGridlines
543
     *
544
     * @throws WriterException
545
     */
546 12
    private function writeValueAxis($objWriter, PlotArea $plotArea, $yAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries, $xAxis, $yAxis, $majorGridlines, $minorGridlines)
0 ignored issues
show
Unused Code introduced by
The parameter $plotArea is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $yAxis is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
547
    {
548 12
        $objWriter->startElement('c:valAx');
549
550 12
        if ($id2 > 0) {
551 12
            $objWriter->startElement('c:axId');
552 12
            $objWriter->writeAttribute('val', $id2);
553 12
            $objWriter->endElement();
554
        }
555
556 12
        $objWriter->startElement('c:scaling');
557
558 12 View Code Duplication
        if (!is_null($xAxis->getAxisOptionsProperty('maximum'))) {
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...
559
            $objWriter->startElement('c:max');
560
            $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('maximum'));
561
            $objWriter->endElement();
562
        }
563
564 12 View Code Duplication
        if (!is_null($xAxis->getAxisOptionsProperty('minimum'))) {
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...
565
            $objWriter->startElement('c:min');
566
            $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minimum'));
567
            $objWriter->endElement();
568
        }
569
570 12
        $objWriter->startElement('c:orientation');
571 12
        $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('orientation'));
572
573 12
        $objWriter->endElement();
574 12
        $objWriter->endElement();
575
576 12
        $objWriter->startElement('c:delete');
577 12
        $objWriter->writeAttribute('val', 0);
578 12
        $objWriter->endElement();
579
580 12
        $objWriter->startElement('c:axPos');
581 12
        $objWriter->writeAttribute('val', 'l');
582 12
        $objWriter->endElement();
583
584 12
        $objWriter->startElement('c:majorGridlines');
585 12
        $objWriter->startElement('c:spPr');
586
587 12 View Code Duplication
        if (!is_null($majorGridlines->getLineColorProperty('value'))) {
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...
588
            $objWriter->startElement('a:ln');
589
            $objWriter->writeAttribute('w', $majorGridlines->getLineStyleProperty('width'));
590
            $objWriter->startElement('a:solidFill');
591
            $objWriter->startElement("a:{$majorGridlines->getLineColorProperty('type')}");
592
            $objWriter->writeAttribute('val', $majorGridlines->getLineColorProperty('value'));
593
            $objWriter->startElement('a:alpha');
594
            $objWriter->writeAttribute('val', $majorGridlines->getLineColorProperty('alpha'));
595
            $objWriter->endElement(); //end alpha
596
            $objWriter->endElement(); //end srgbClr
597
            $objWriter->endElement(); //end solidFill
598
599
            $objWriter->startElement('a:prstDash');
600
            $objWriter->writeAttribute('val', $majorGridlines->getLineStyleProperty('dash'));
601
            $objWriter->endElement();
602
603
            if ($majorGridlines->getLineStyleProperty('join') == 'miter') {
604
                $objWriter->startElement('a:miter');
605
                $objWriter->writeAttribute('lim', '800000');
606
                $objWriter->endElement();
607
            } else {
608
                $objWriter->startElement('a:bevel');
609
                $objWriter->endElement();
610
            }
611
612
            if (!is_null($majorGridlines->getLineStyleProperty(['arrow', 'head', 'type']))) {
613
                $objWriter->startElement('a:headEnd');
614
                $objWriter->writeAttribute('type', $majorGridlines->getLineStyleProperty(['arrow', 'head', 'type']));
615
                $objWriter->writeAttribute('w', $majorGridlines->getLineStyleArrowParameters('head', 'w'));
616
                $objWriter->writeAttribute('len', $majorGridlines->getLineStyleArrowParameters('head', 'len'));
617
                $objWriter->endElement();
618
            }
619
620
            if (!is_null($majorGridlines->getLineStyleProperty(['arrow', 'end', 'type']))) {
621
                $objWriter->startElement('a:tailEnd');
622
                $objWriter->writeAttribute('type', $majorGridlines->getLineStyleProperty(['arrow', 'end', 'type']));
623
                $objWriter->writeAttribute('w', $majorGridlines->getLineStyleArrowParameters('end', 'w'));
624
                $objWriter->writeAttribute('len', $majorGridlines->getLineStyleArrowParameters('end', 'len'));
625
                $objWriter->endElement();
626
            }
627
            $objWriter->endElement(); //end ln
628
        }
629 12
        $objWriter->startElement('a:effectLst');
630
631 12 View Code Duplication
        if (!is_null($majorGridlines->getGlowSize())) {
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...
632
            $objWriter->startElement('a:glow');
633
            $objWriter->writeAttribute('rad', $majorGridlines->getGlowSize());
634
            $objWriter->startElement("a:{$majorGridlines->getGlowColor('type')}");
635
            $objWriter->writeAttribute('val', $majorGridlines->getGlowColor('value'));
636
            $objWriter->startElement('a:alpha');
637
            $objWriter->writeAttribute('val', $majorGridlines->getGlowColor('alpha'));
638
            $objWriter->endElement(); //end alpha
639
            $objWriter->endElement(); //end schemeClr
640
            $objWriter->endElement(); //end glow
641
        }
642
643 12 View Code Duplication
        if (!is_null($majorGridlines->getShadowProperty('presets'))) {
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...
644
            $objWriter->startElement("a:{$majorGridlines->getShadowProperty('effect')}");
645
            if (!is_null($majorGridlines->getShadowProperty('blur'))) {
646
                $objWriter->writeAttribute('blurRad', $majorGridlines->getShadowProperty('blur'));
647
            }
648
            if (!is_null($majorGridlines->getShadowProperty('distance'))) {
649
                $objWriter->writeAttribute('dist', $majorGridlines->getShadowProperty('distance'));
650
            }
651
            if (!is_null($majorGridlines->getShadowProperty('direction'))) {
652
                $objWriter->writeAttribute('dir', $majorGridlines->getShadowProperty('direction'));
653
            }
654
            if (!is_null($majorGridlines->getShadowProperty('algn'))) {
655
                $objWriter->writeAttribute('algn', $majorGridlines->getShadowProperty('algn'));
656
            }
657
            if (!is_null($majorGridlines->getShadowProperty(['size', 'sx']))) {
658
                $objWriter->writeAttribute('sx', $majorGridlines->getShadowProperty(['size', 'sx']));
659
            }
660
            if (!is_null($majorGridlines->getShadowProperty(['size', 'sy']))) {
661
                $objWriter->writeAttribute('sy', $majorGridlines->getShadowProperty(['size', 'sy']));
662
            }
663
            if (!is_null($majorGridlines->getShadowProperty(['size', 'kx']))) {
664
                $objWriter->writeAttribute('kx', $majorGridlines->getShadowProperty(['size', 'kx']));
665
            }
666
            if (!is_null($majorGridlines->getShadowProperty('rotWithShape'))) {
667
                $objWriter->writeAttribute('rotWithShape', $majorGridlines->getShadowProperty('rotWithShape'));
668
            }
669
            $objWriter->startElement("a:{$majorGridlines->getShadowProperty(['color', 'type'])}");
670
            $objWriter->writeAttribute('val', $majorGridlines->getShadowProperty(['color', 'value']));
671
672
            $objWriter->startElement('a:alpha');
673
            $objWriter->writeAttribute('val', $majorGridlines->getShadowProperty(['color', 'alpha']));
674
            $objWriter->endElement(); //end alpha
675
676
            $objWriter->endElement(); //end color:type
677
            $objWriter->endElement(); //end shadow
678
        }
679
680 12 View Code Duplication
        if (!is_null($majorGridlines->getSoftEdgesSize())) {
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...
681
            $objWriter->startElement('a:softEdge');
682
            $objWriter->writeAttribute('rad', $majorGridlines->getSoftEdgesSize());
683
            $objWriter->endElement(); //end softEdge
684
        }
685
686 12
        $objWriter->endElement(); //end effectLst
687 12
        $objWriter->endElement(); //end spPr
688 12
        $objWriter->endElement(); //end majorGridLines
689
690 12
        if ($minorGridlines->getObjectState()) {
691
            $objWriter->startElement('c:minorGridlines');
692
            $objWriter->startElement('c:spPr');
693
694 View Code Duplication
            if (!is_null($minorGridlines->getLineColorProperty('value'))) {
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...
695
                $objWriter->startElement('a:ln');
696
                $objWriter->writeAttribute('w', $minorGridlines->getLineStyleProperty('width'));
697
                $objWriter->startElement('a:solidFill');
698
                $objWriter->startElement("a:{$minorGridlines->getLineColorProperty('type')}");
699
                $objWriter->writeAttribute('val', $minorGridlines->getLineColorProperty('value'));
700
                $objWriter->startElement('a:alpha');
701
                $objWriter->writeAttribute('val', $minorGridlines->getLineColorProperty('alpha'));
702
                $objWriter->endElement(); //end alpha
703
                $objWriter->endElement(); //end srgbClr
704
                $objWriter->endElement(); //end solidFill
705
706
                $objWriter->startElement('a:prstDash');
707
                $objWriter->writeAttribute('val', $minorGridlines->getLineStyleProperty('dash'));
708
                $objWriter->endElement();
709
710
                if ($minorGridlines->getLineStyleProperty('join') == 'miter') {
711
                    $objWriter->startElement('a:miter');
712
                    $objWriter->writeAttribute('lim', '800000');
713
                    $objWriter->endElement();
714
                } else {
715
                    $objWriter->startElement('a:bevel');
716
                    $objWriter->endElement();
717
                }
718
719
                if (!is_null($minorGridlines->getLineStyleProperty(['arrow', 'head', 'type']))) {
720
                    $objWriter->startElement('a:headEnd');
721
                    $objWriter->writeAttribute('type', $minorGridlines->getLineStyleProperty(['arrow', 'head', 'type']));
722
                    $objWriter->writeAttribute('w', $minorGridlines->getLineStyleArrowParameters('head', 'w'));
723
                    $objWriter->writeAttribute('len', $minorGridlines->getLineStyleArrowParameters('head', 'len'));
724
                    $objWriter->endElement();
725
                }
726
727
                if (!is_null($minorGridlines->getLineStyleProperty(['arrow', 'end', 'type']))) {
728
                    $objWriter->startElement('a:tailEnd');
729
                    $objWriter->writeAttribute('type', $minorGridlines->getLineStyleProperty(['arrow', 'end', 'type']));
730
                    $objWriter->writeAttribute('w', $minorGridlines->getLineStyleArrowParameters('end', 'w'));
731
                    $objWriter->writeAttribute('len', $minorGridlines->getLineStyleArrowParameters('end', 'len'));
732
                    $objWriter->endElement();
733
                }
734
                $objWriter->endElement(); //end ln
735
            }
736
737
            $objWriter->startElement('a:effectLst');
738
739 View Code Duplication
            if (!is_null($minorGridlines->getGlowSize())) {
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...
740
                $objWriter->startElement('a:glow');
741
                $objWriter->writeAttribute('rad', $minorGridlines->getGlowSize());
742
                $objWriter->startElement("a:{$minorGridlines->getGlowColor('type')}");
743
                $objWriter->writeAttribute('val', $minorGridlines->getGlowColor('value'));
744
                $objWriter->startElement('a:alpha');
745
                $objWriter->writeAttribute('val', $minorGridlines->getGlowColor('alpha'));
746
                $objWriter->endElement(); //end alpha
747
                $objWriter->endElement(); //end schemeClr
748
                $objWriter->endElement(); //end glow
749
            }
750
751 View Code Duplication
            if (!is_null($minorGridlines->getShadowProperty('presets'))) {
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...
752
                $objWriter->startElement("a:{$minorGridlines->getShadowProperty('effect')}");
753
                if (!is_null($minorGridlines->getShadowProperty('blur'))) {
754
                    $objWriter->writeAttribute('blurRad', $minorGridlines->getShadowProperty('blur'));
755
                }
756
                if (!is_null($minorGridlines->getShadowProperty('distance'))) {
757
                    $objWriter->writeAttribute('dist', $minorGridlines->getShadowProperty('distance'));
758
                }
759
                if (!is_null($minorGridlines->getShadowProperty('direction'))) {
760
                    $objWriter->writeAttribute('dir', $minorGridlines->getShadowProperty('direction'));
761
                }
762
                if (!is_null($minorGridlines->getShadowProperty('algn'))) {
763
                    $objWriter->writeAttribute('algn', $minorGridlines->getShadowProperty('algn'));
764
                }
765
                if (!is_null($minorGridlines->getShadowProperty(['size', 'sx']))) {
766
                    $objWriter->writeAttribute('sx', $minorGridlines->getShadowProperty(['size', 'sx']));
767
                }
768
                if (!is_null($minorGridlines->getShadowProperty(['size', 'sy']))) {
769
                    $objWriter->writeAttribute('sy', $minorGridlines->getShadowProperty(['size', 'sy']));
770
                }
771
                if (!is_null($minorGridlines->getShadowProperty(['size', 'kx']))) {
772
                    $objWriter->writeAttribute('kx', $minorGridlines->getShadowProperty(['size', 'kx']));
773
                }
774
                if (!is_null($minorGridlines->getShadowProperty('rotWithShape'))) {
775
                    $objWriter->writeAttribute('rotWithShape', $minorGridlines->getShadowProperty('rotWithShape'));
776
                }
777
                $objWriter->startElement("a:{$minorGridlines->getShadowProperty(['color', 'type'])}");
778
                $objWriter->writeAttribute('val', $minorGridlines->getShadowProperty(['color', 'value']));
779
                $objWriter->startElement('a:alpha');
780
                $objWriter->writeAttribute('val', $minorGridlines->getShadowProperty(['color', 'alpha']));
781
                $objWriter->endElement(); //end alpha
782
                $objWriter->endElement(); //end color:type
783
                $objWriter->endElement(); //end shadow
784
            }
785
786 View Code Duplication
            if (!is_null($minorGridlines->getSoftEdgesSize())) {
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...
787
                $objWriter->startElement('a:softEdge');
788
                $objWriter->writeAttribute('rad', $minorGridlines->getSoftEdgesSize());
789
                $objWriter->endElement(); //end softEdge
790
            }
791
792
            $objWriter->endElement(); //end effectLst
793
            $objWriter->endElement(); //end spPr
794
            $objWriter->endElement(); //end minorGridLines
795
        }
796
797 12 View Code Duplication
        if (!is_null($yAxisLabel)) {
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...
798 10
            $objWriter->startElement('c:title');
799 10
            $objWriter->startElement('c:tx');
800 10
            $objWriter->startElement('c:rich');
801
802 10
            $objWriter->startElement('a:bodyPr');
803 10
            $objWriter->endElement();
804
805 10
            $objWriter->startElement('a:lstStyle');
806 10
            $objWriter->endElement();
807
808 10
            $objWriter->startElement('a:p');
809 10
            $objWriter->startElement('a:r');
810
811 10
            $caption = $yAxisLabel->getCaption();
812 10
            if (is_array($caption)) {
813 1
                $caption = $caption[0];
814
            }
815
816 10
            $objWriter->startElement('a:t');
817 10
            $objWriter->writeRawData(StringHelper::controlCharacterPHP2OOXML($caption));
818 10
            $objWriter->endElement();
819
820 10
            $objWriter->endElement();
821 10
            $objWriter->endElement();
822 10
            $objWriter->endElement();
823 10
            $objWriter->endElement();
824
825 10
            if ($groupType !== DataSeries::TYPE_BUBBLECHART) {
826 10
                $layout = $yAxisLabel->getLayout();
827 10
                $this->writeLayout($objWriter, $layout);
828
            }
829
830 10
            $objWriter->startElement('c:overlay');
831 10
            $objWriter->writeAttribute('val', 0);
832 10
            $objWriter->endElement();
833
834 10
            $objWriter->endElement();
835
        }
836
837 12
        $objWriter->startElement('c:numFmt');
838 12
        $objWriter->writeAttribute('formatCode', $xAxis->getAxisNumberFormat());
839 12
        $objWriter->writeAttribute('sourceLinked', $xAxis->getAxisNumberSourceLinked());
840 12
        $objWriter->endElement();
841
842 12
        $objWriter->startElement('c:majorTickMark');
843 12
        $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('major_tick_mark'));
844 12
        $objWriter->endElement();
845
846 12
        $objWriter->startElement('c:minorTickMark');
847 12
        $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minor_tick_mark'));
848 12
        $objWriter->endElement();
849
850 12
        $objWriter->startElement('c:tickLblPos');
851 12
        $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('axis_labels'));
852 12
        $objWriter->endElement();
853
854 12
        $objWriter->startElement('c:spPr');
855
856 12 View Code Duplication
        if (!is_null($xAxis->getFillProperty('value'))) {
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...
857
            $objWriter->startElement('a:solidFill');
858
            $objWriter->startElement('a:' . $xAxis->getFillProperty('type'));
859
            $objWriter->writeAttribute('val', $xAxis->getFillProperty('value'));
860
            $objWriter->startElement('a:alpha');
861
            $objWriter->writeAttribute('val', $xAxis->getFillProperty('alpha'));
862
            $objWriter->endElement();
863
            $objWriter->endElement();
864
            $objWriter->endElement();
865
        }
866
867 12
        $objWriter->startElement('a:ln');
868
869 12
        $objWriter->writeAttribute('w', $xAxis->getLineStyleProperty('width'));
870 12
        $objWriter->writeAttribute('cap', $xAxis->getLineStyleProperty('cap'));
871 12
        $objWriter->writeAttribute('cmpd', $xAxis->getLineStyleProperty('compound'));
872
873 12 View Code Duplication
        if (!is_null($xAxis->getLineProperty('value'))) {
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...
874
            $objWriter->startElement('a:solidFill');
875
            $objWriter->startElement('a:' . $xAxis->getLineProperty('type'));
876
            $objWriter->writeAttribute('val', $xAxis->getLineProperty('value'));
877
            $objWriter->startElement('a:alpha');
878
            $objWriter->writeAttribute('val', $xAxis->getLineProperty('alpha'));
879
            $objWriter->endElement();
880
            $objWriter->endElement();
881
            $objWriter->endElement();
882
        }
883
884 12
        $objWriter->startElement('a:prstDash');
885 12
        $objWriter->writeAttribute('val', $xAxis->getLineStyleProperty('dash'));
886 12
        $objWriter->endElement();
887
888 12
        if ($xAxis->getLineStyleProperty('join') == 'miter') {
889
            $objWriter->startElement('a:miter');
890
            $objWriter->writeAttribute('lim', '800000');
891
            $objWriter->endElement();
892
        } else {
893 12
            $objWriter->startElement('a:bevel');
894 12
            $objWriter->endElement();
895
        }
896
897 12
        if (!is_null($xAxis->getLineStyleProperty(['arrow', 'head', 'type']))) {
898
            $objWriter->startElement('a:headEnd');
899
            $objWriter->writeAttribute('type', $xAxis->getLineStyleProperty(['arrow', 'head', 'type']));
900
            $objWriter->writeAttribute('w', $xAxis->getLineStyleArrowWidth('head'));
901
            $objWriter->writeAttribute('len', $xAxis->getLineStyleArrowLength('head'));
902
            $objWriter->endElement();
903
        }
904
905 12
        if (!is_null($xAxis->getLineStyleProperty(['arrow', 'end', 'type']))) {
906
            $objWriter->startElement('a:tailEnd');
907
            $objWriter->writeAttribute('type', $xAxis->getLineStyleProperty(['arrow', 'end', 'type']));
908
            $objWriter->writeAttribute('w', $xAxis->getLineStyleArrowWidth('end'));
909
            $objWriter->writeAttribute('len', $xAxis->getLineStyleArrowLength('end'));
910
            $objWriter->endElement();
911
        }
912
913 12
        $objWriter->endElement();
914
915 12
        $objWriter->startElement('a:effectLst');
916
917 12
        if (!is_null($xAxis->getGlowProperty('size'))) {
918
            $objWriter->startElement('a:glow');
919
            $objWriter->writeAttribute('rad', $xAxis->getGlowProperty('size'));
920
            $objWriter->startElement("a:{$xAxis->getGlowProperty(['color', 'type'])}");
921
            $objWriter->writeAttribute('val', $xAxis->getGlowProperty(['color', 'value']));
922
            $objWriter->startElement('a:alpha');
923
            $objWriter->writeAttribute('val', $xAxis->getGlowProperty(['color', 'alpha']));
924
            $objWriter->endElement();
925
            $objWriter->endElement();
926
            $objWriter->endElement();
927
        }
928
929 12 View Code Duplication
        if (!is_null($xAxis->getShadowProperty('presets'))) {
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...
930
            $objWriter->startElement("a:{$xAxis->getShadowProperty('effect')}");
931
932
            if (!is_null($xAxis->getShadowProperty('blur'))) {
933
                $objWriter->writeAttribute('blurRad', $xAxis->getShadowProperty('blur'));
934
            }
935
            if (!is_null($xAxis->getShadowProperty('distance'))) {
936
                $objWriter->writeAttribute('dist', $xAxis->getShadowProperty('distance'));
937
            }
938
            if (!is_null($xAxis->getShadowProperty('direction'))) {
939
                $objWriter->writeAttribute('dir', $xAxis->getShadowProperty('direction'));
940
            }
941
            if (!is_null($xAxis->getShadowProperty('algn'))) {
942
                $objWriter->writeAttribute('algn', $xAxis->getShadowProperty('algn'));
943
            }
944
            if (!is_null($xAxis->getShadowProperty(['size', 'sx']))) {
945
                $objWriter->writeAttribute('sx', $xAxis->getShadowProperty(['size', 'sx']));
946
            }
947
            if (!is_null($xAxis->getShadowProperty(['size', 'sy']))) {
948
                $objWriter->writeAttribute('sy', $xAxis->getShadowProperty(['size', 'sy']));
949
            }
950
            if (!is_null($xAxis->getShadowProperty(['size', 'kx']))) {
951
                $objWriter->writeAttribute('kx', $xAxis->getShadowProperty(['size', 'kx']));
952
            }
953
            if (!is_null($xAxis->getShadowProperty('rotWithShape'))) {
954
                $objWriter->writeAttribute('rotWithShape', $xAxis->getShadowProperty('rotWithShape'));
955
            }
956
957
            $objWriter->startElement("a:{$xAxis->getShadowProperty(['color', 'type'])}");
958
            $objWriter->writeAttribute('val', $xAxis->getShadowProperty(['color', 'value']));
959
            $objWriter->startElement('a:alpha');
960
            $objWriter->writeAttribute('val', $xAxis->getShadowProperty(['color', 'alpha']));
961
            $objWriter->endElement();
962
            $objWriter->endElement();
963
964
            $objWriter->endElement();
965
        }
966
967 12 View Code Duplication
        if (!is_null($xAxis->getSoftEdgesSize())) {
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...
968
            $objWriter->startElement('a:softEdge');
969
            $objWriter->writeAttribute('rad', $xAxis->getSoftEdgesSize());
970
            $objWriter->endElement();
971
        }
972
973 12
        $objWriter->endElement(); //effectList
974 12
        $objWriter->endElement(); //end spPr
975
976 12
        if ($id1 > 0) {
977 12
            $objWriter->startElement('c:crossAx');
978 12
            $objWriter->writeAttribute('val', $id2);
979 12
            $objWriter->endElement();
980
981 12
            if (!is_null($xAxis->getAxisOptionsProperty('horizontal_crosses_value'))) {
982
                $objWriter->startElement('c:crossesAt');
983
                $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('horizontal_crosses_value'));
984
                $objWriter->endElement();
985
            } else {
986 12
                $objWriter->startElement('c:crosses');
987 12
                $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('horizontal_crosses'));
988 12
                $objWriter->endElement();
989
            }
990
991 12
            $objWriter->startElement('c:crossBetween');
992 12
            $objWriter->writeAttribute('val', 'midCat');
993 12
            $objWriter->endElement();
994
995 12 View Code Duplication
            if (!is_null($xAxis->getAxisOptionsProperty('major_unit'))) {
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...
996
                $objWriter->startElement('c:majorUnit');
997
                $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('major_unit'));
998
                $objWriter->endElement();
999
            }
1000
1001 12 View Code Duplication
            if (!is_null($xAxis->getAxisOptionsProperty('minor_unit'))) {
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...
1002
                $objWriter->startElement('c:minorUnit');
1003
                $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minor_unit'));
1004
                $objWriter->endElement();
1005
            }
1006
        }
1007
1008 12
        if ($isMultiLevelSeries) {
1009 1
            if ($groupType !== DataSeries::TYPE_BUBBLECHART) {
1010
                $objWriter->startElement('c:noMultiLvlLbl');
1011
                $objWriter->writeAttribute('val', 0);
1012
                $objWriter->endElement();
1013
            }
1014
        }
1015
1016 12
        $objWriter->endElement();
1017 12
    }
1018
1019
    /**
1020
     * Get the data series type(s) for a chart plot series.
1021
     *
1022
     * @param PlotArea $plotArea
1023
     *
1024
     * @throws WriterException
1025
     *
1026
     * @return string|array
1027
     */
1028 13
    private static function getChartType($plotArea)
1029
    {
1030 13
        $groupCount = $plotArea->getPlotGroupCount();
1031
1032 13
        if ($groupCount == 1) {
1033 12
            $chartType = [$plotArea->getPlotGroupByIndex(0)->getPlotType()];
1034
        } else {
1035 2
            $chartTypes = [];
1036 2
            for ($i = 0; $i < $groupCount; ++$i) {
1037 2
                $chartTypes[] = $plotArea->getPlotGroupByIndex($i)->getPlotType();
1038
            }
1039 2
            $chartType = array_unique($chartTypes);
1040 2
            if (count($chartTypes) == 0) {
1041
                throw new WriterException('Chart is not yet implemented');
1042
            }
1043
        }
1044
1045 13
        return $chartType;
1046
    }
1047
1048
    /**
1049
     * Write Plot Group (series of related plots).
1050
     *
1051
     * @param DataSeries $plotGroup
1052
     * @param string $groupType Type of plot for dataseries
1053
     * @param XMLWriter $objWriter XML Writer
1054
     * @param bool &$catIsMultiLevelSeries Is category a multi-series category
1055
     * @param bool &$valIsMultiLevelSeries Is value set a multi-series set
1056
     * @param string &$plotGroupingType Type of grouping for multi-series values
1057
     * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet
1058
     *
1059
     * @throws WriterException
1060
     */
1061 13
    private function writePlotGroup($plotGroup, $groupType, $objWriter, &$catIsMultiLevelSeries, &$valIsMultiLevelSeries, &$plotGroupingType, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet)
0 ignored issues
show
Unused Code introduced by
The parameter $pSheet is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1062
    {
1063 13
        if (is_null($plotGroup)) {
1064
            return;
1065
        }
1066
1067 13
        if (($groupType == DataSeries::TYPE_BARCHART) || ($groupType == DataSeries::TYPE_BARCHART_3D)) {
1068 7
            $objWriter->startElement('c:barDir');
1069 7
            $objWriter->writeAttribute('val', $plotGroup->getPlotDirection());
1070 7
            $objWriter->endElement();
1071
        }
1072
1073 13 View Code Duplication
        if (!is_null($plotGroup->getPlotGrouping())) {
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...
1074 9
            $plotGroupingType = $plotGroup->getPlotGrouping();
1075 9
            $objWriter->startElement('c:grouping');
1076 9
            $objWriter->writeAttribute('val', $plotGroupingType);
1077 9
            $objWriter->endElement();
1078
        }
1079
1080
        //    Get these details before the loop, because we can use the count to check for varyColors
1081 13
        $plotSeriesOrder = $plotGroup->getPlotOrder();
1082 13
        $plotSeriesCount = count($plotSeriesOrder);
1083
1084 13
        if (($groupType !== DataSeries::TYPE_RADARCHART) && ($groupType !== DataSeries::TYPE_STOCKCHART)) {
1085 11
            if ($groupType !== DataSeries::TYPE_LINECHART) {
1086 10
                if (($groupType == DataSeries::TYPE_PIECHART) || ($groupType == DataSeries::TYPE_PIECHART_3D) || ($groupType == DataSeries::TYPE_DONUTCHART) || ($plotSeriesCount > 1)) {
1087 9
                    $objWriter->startElement('c:varyColors');
1088 9
                    $objWriter->writeAttribute('val', 1);
1089 9
                    $objWriter->endElement();
1090
                } else {
1091 2
                    $objWriter->startElement('c:varyColors');
1092 2
                    $objWriter->writeAttribute('val', 0);
1093 2
                    $objWriter->endElement();
1094
                }
1095
            }
1096
        }
1097
1098 13
        foreach ($plotSeriesOrder as $plotSeriesIdx => $plotSeriesRef) {
1099 13
            $objWriter->startElement('c:ser');
1100
1101 13
            $plotLabel = $plotGroup->getPlotLabelByIndex($plotSeriesIdx);
1102 13
            if ($plotLabel) {
1103 13
                $fillColor = $plotLabel->getFillColor();
1104 13
                if ($fillColor !== null) {
1105
                    $objWriter->startElement('c:spPr');
1106
                    $objWriter->startElement('a:solidFill');
1107
                    $objWriter->startElement('a:srgbClr');
1108
                    $objWriter->writeAttribute('val', $fillColor);
1109
                    $objWriter->endElement();
1110
                    $objWriter->endElement();
1111
                    $objWriter->endElement();
1112
                }
1113
            }
1114
1115 13
            $objWriter->startElement('c:idx');
1116 13
            $objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesIdx);
1117 13
            $objWriter->endElement();
1118
1119 13
            $objWriter->startElement('c:order');
1120 13
            $objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesRef);
1121 13
            $objWriter->endElement();
1122
1123 13
            if (($groupType == DataSeries::TYPE_PIECHART) || ($groupType == DataSeries::TYPE_PIECHART_3D) || ($groupType == DataSeries::TYPE_DONUTCHART)) {
1124 2
                $objWriter->startElement('c:dPt');
1125 2
                $objWriter->startElement('c:idx');
1126 2
                $objWriter->writeAttribute('val', 3);
1127 2
                $objWriter->endElement();
1128
1129 2
                $objWriter->startElement('c:bubble3D');
1130 2
                $objWriter->writeAttribute('val', 0);
1131 2
                $objWriter->endElement();
1132
1133 2
                $objWriter->startElement('c:spPr');
1134 2
                $objWriter->startElement('a:solidFill');
1135 2
                $objWriter->startElement('a:srgbClr');
1136 2
                $objWriter->writeAttribute('val', 'FF9900');
1137 2
                $objWriter->endElement();
1138 2
                $objWriter->endElement();
1139 2
                $objWriter->endElement();
1140 2
                $objWriter->endElement();
1141
            }
1142
1143
            //    Labels
1144 13
            $plotSeriesLabel = $plotGroup->getPlotLabelByIndex($plotSeriesRef);
1145 13
            if ($plotSeriesLabel && ($plotSeriesLabel->getPointCount() > 0)) {
1146 13
                $objWriter->startElement('c:tx');
1147 13
                $objWriter->startElement('c:strRef');
1148 13
                $this->writePlotSeriesLabel($plotSeriesLabel, $objWriter);
1149 13
                $objWriter->endElement();
1150 13
                $objWriter->endElement();
1151
            }
1152
1153
            //    Formatting for the points
1154 13
            if (($groupType == DataSeries::TYPE_LINECHART) || ($groupType == DataSeries::TYPE_STOCKCHART)) {
1155 4
                $objWriter->startElement('c:spPr');
1156 4
                $objWriter->startElement('a:ln');
1157 4
                $objWriter->writeAttribute('w', 12700);
1158 4
                if ($groupType == DataSeries::TYPE_STOCKCHART) {
1159 2
                    $objWriter->startElement('a:noFill');
1160 2
                    $objWriter->endElement();
1161
                }
1162 4
                $objWriter->endElement();
1163 4
                $objWriter->endElement();
1164
            }
1165
1166 13
            $plotSeriesValues = $plotGroup->getPlotValuesByIndex($plotSeriesRef);
1167 13
            if ($plotSeriesValues) {
1168 13
                $plotSeriesMarker = $plotSeriesValues->getPointMarker();
1169 13
                if ($plotSeriesMarker) {
1170 1
                    $objWriter->startElement('c:marker');
1171 1
                    $objWriter->startElement('c:symbol');
1172 1
                    $objWriter->writeAttribute('val', $plotSeriesMarker);
1173 1
                    $objWriter->endElement();
1174
1175 1
                    if ($plotSeriesMarker !== 'none') {
1176 1
                        $objWriter->startElement('c:size');
1177 1
                        $objWriter->writeAttribute('val', 3);
1178 1
                        $objWriter->endElement();
1179
                    }
1180
1181 1
                    $objWriter->endElement();
1182
                }
1183
            }
1184
1185 13
            if (($groupType === DataSeries::TYPE_BARCHART) || ($groupType === DataSeries::TYPE_BARCHART_3D) || ($groupType === DataSeries::TYPE_BUBBLECHART)) {
1186 7
                $objWriter->startElement('c:invertIfNegative');
1187 7
                $objWriter->writeAttribute('val', 0);
1188 7
                $objWriter->endElement();
1189
            }
1190
1191
            //    Category Labels
1192 13
            $plotSeriesCategory = $plotGroup->getPlotCategoryByIndex($plotSeriesRef);
1193 13
            if ($plotSeriesCategory && ($plotSeriesCategory->getPointCount() > 0)) {
1194 13
                $catIsMultiLevelSeries = $catIsMultiLevelSeries || $plotSeriesCategory->isMultiLevelSeries();
1195
1196 13
                if (($groupType == DataSeries::TYPE_PIECHART) || ($groupType == DataSeries::TYPE_PIECHART_3D) || ($groupType == DataSeries::TYPE_DONUTCHART)) {
1197 2 View Code Duplication
                    if (!is_null($plotGroup->getPlotStyle())) {
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...
1198 1
                        $plotStyle = $plotGroup->getPlotStyle();
1199 1
                        if ($plotStyle) {
1200 1
                            $objWriter->startElement('c:explosion');
1201 1
                            $objWriter->writeAttribute('val', 25);
1202 1
                            $objWriter->endElement();
1203
                        }
1204
                    }
1205
                }
1206
1207 13
                if (($groupType === DataSeries::TYPE_BUBBLECHART) || ($groupType === DataSeries::TYPE_SCATTERCHART)) {
1208 2
                    $objWriter->startElement('c:xVal');
1209
                } else {
1210 12
                    $objWriter->startElement('c:cat');
1211
                }
1212
1213 13
                $this->writePlotSeriesValues($plotSeriesCategory, $objWriter, $groupType, 'str');
1214 13
                $objWriter->endElement();
1215
            }
1216
1217
            //    Values
1218 13
            if ($plotSeriesValues) {
1219 13
                $valIsMultiLevelSeries = $valIsMultiLevelSeries || $plotSeriesValues->isMultiLevelSeries();
1220
1221 13
                if (($groupType === DataSeries::TYPE_BUBBLECHART) || ($groupType === DataSeries::TYPE_SCATTERCHART)) {
1222 2
                    $objWriter->startElement('c:yVal');
1223
                } else {
1224 12
                    $objWriter->startElement('c:val');
1225
                }
1226
1227 13
                $this->writePlotSeriesValues($plotSeriesValues, $objWriter, $groupType, 'num');
1228 13
                $objWriter->endElement();
1229
            }
1230
1231 13
            if ($groupType === DataSeries::TYPE_BUBBLECHART) {
1232 1
                $this->writeBubbles($plotSeriesValues, $objWriter);
1233
            }
1234
1235 13
            $objWriter->endElement();
1236
        }
1237
1238 13
        $this->_seriesIndex += $plotSeriesIdx + 1;
0 ignored issues
show
Bug introduced by
The variable $plotSeriesIdx seems to be defined by a foreach iteration on line 1098. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
1239 13
    }
1240
1241
    /**
1242
     * Write Plot Series Label.
1243
     *
1244
     * @param DataSeriesValues $plotSeriesLabel
1245
     * @param XMLWriter $objWriter XML Writer
1246
     *
1247
     * @throws WriterException
1248
     */
1249 13
    private function writePlotSeriesLabel($plotSeriesLabel, $objWriter)
1250
    {
1251 13
        if (is_null($plotSeriesLabel)) {
1252
            return;
1253
        }
1254
1255 13
        $objWriter->startElement('c:f');
1256 13
        $objWriter->writeRawData($plotSeriesLabel->getDataSource());
1257 13
        $objWriter->endElement();
1258
1259 13
        $objWriter->startElement('c:strCache');
1260 13
        $objWriter->startElement('c:ptCount');
1261 13
        $objWriter->writeAttribute('val', $plotSeriesLabel->getPointCount());
1262 13
        $objWriter->endElement();
1263
1264 13
        foreach ($plotSeriesLabel->getDataValues() as $plotLabelKey => $plotLabelValue) {
1265 13
            $objWriter->startElement('c:pt');
1266 13
            $objWriter->writeAttribute('idx', $plotLabelKey);
1267
1268 13
            $objWriter->startElement('c:v');
1269 13
            $objWriter->writeRawData($plotLabelValue);
1270 13
            $objWriter->endElement();
1271 13
            $objWriter->endElement();
1272
        }
1273 13
        $objWriter->endElement();
1274 13
    }
1275
1276
    /**
1277
     * Write Plot Series Values.
1278
     *
1279
     * @param DataSeriesValues $plotSeriesValues
1280
     * @param XMLWriter $objWriter XML Writer
1281
     * @param string $groupType Type of plot for dataseries
1282
     * @param string $dataType Datatype of series values
1283
     *
1284
     * @throws WriterException
1285
     */
1286 13
    private function writePlotSeriesValues($plotSeriesValues, XMLWriter $objWriter, $groupType, $dataType = 'str')
1287
    {
1288 13
        if (is_null($plotSeriesValues)) {
1289
            return;
1290
        }
1291
1292 13
        if ($plotSeriesValues->isMultiLevelSeries()) {
1293 2
            $levelCount = $plotSeriesValues->multiLevelCount();
1294
1295 2
            $objWriter->startElement('c:multiLvlStrRef');
1296
1297 2
            $objWriter->startElement('c:f');
1298 2
            $objWriter->writeRawData($plotSeriesValues->getDataSource());
1299 2
            $objWriter->endElement();
1300
1301 2
            $objWriter->startElement('c:multiLvlStrCache');
1302
1303 2
            $objWriter->startElement('c:ptCount');
1304 2
            $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount());
1305 2
            $objWriter->endElement();
1306
1307 2
            for ($level = 0; $level < $levelCount; ++$level) {
1308 2
                $objWriter->startElement('c:lvl');
1309
1310 2
                foreach ($plotSeriesValues->getDataValues() as $plotSeriesKey => $plotSeriesValue) {
1311 2
                    if (isset($plotSeriesValue[$level])) {
1312 2
                        $objWriter->startElement('c:pt');
1313 2
                        $objWriter->writeAttribute('idx', $plotSeriesKey);
1314
1315 2
                        $objWriter->startElement('c:v');
1316 2
                        $objWriter->writeRawData($plotSeriesValue[$level]);
1317 2
                        $objWriter->endElement();
1318 2
                        $objWriter->endElement();
1319
                    }
1320
                }
1321
1322 2
                $objWriter->endElement();
1323
            }
1324
1325 2
            $objWriter->endElement();
1326
1327 2
            $objWriter->endElement();
1328
        } else {
1329 13
            $objWriter->startElement('c:' . $dataType . 'Ref');
1330
1331 13
            $objWriter->startElement('c:f');
1332 13
            $objWriter->writeRawData($plotSeriesValues->getDataSource());
1333 13
            $objWriter->endElement();
1334
1335 13
            $objWriter->startElement('c:' . $dataType . 'Cache');
1336
1337 13
            if (($groupType != DataSeries::TYPE_PIECHART) && ($groupType != DataSeries::TYPE_PIECHART_3D) && ($groupType != DataSeries::TYPE_DONUTCHART)) {
1338 12
                if (($plotSeriesValues->getFormatCode() !== null) && ($plotSeriesValues->getFormatCode() !== '')) {
1339 1
                    $objWriter->startElement('c:formatCode');
1340 1
                    $objWriter->writeRawData($plotSeriesValues->getFormatCode());
1341 1
                    $objWriter->endElement();
1342
                }
1343
            }
1344
1345 13
            $objWriter->startElement('c:ptCount');
1346 13
            $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount());
1347 13
            $objWriter->endElement();
1348
1349 13
            $dataValues = $plotSeriesValues->getDataValues();
1350 13
            if (!empty($dataValues)) {
1351 13
                if (is_array($dataValues)) {
1352 13
                    foreach ($dataValues as $plotSeriesKey => $plotSeriesValue) {
1353 13
                        $objWriter->startElement('c:pt');
1354 13
                        $objWriter->writeAttribute('idx', $plotSeriesKey);
1355
1356 13
                        $objWriter->startElement('c:v');
1357 13
                        $objWriter->writeRawData($plotSeriesValue);
1358 13
                        $objWriter->endElement();
1359 13
                        $objWriter->endElement();
1360
                    }
1361
                }
1362
            }
1363
1364 13
            $objWriter->endElement();
1365
1366 13
            $objWriter->endElement();
1367
        }
1368 13
    }
1369
1370
    /**
1371
     * Write Bubble Chart Details.
1372
     *
1373
     * @param DataSeriesValues $plotSeriesValues
1374
     * @param XMLWriter $objWriter XML Writer
1375
     *
1376
     * @throws WriterException
1377
     */
1378 1
    private function writeBubbles($plotSeriesValues, $objWriter)
1379
    {
1380 1
        if (is_null($plotSeriesValues)) {
1381
            return;
1382
        }
1383
1384 1
        $objWriter->startElement('c:bubbleSize');
1385 1
        $objWriter->startElement('c:numLit');
1386
1387 1
        $objWriter->startElement('c:formatCode');
1388 1
        $objWriter->writeRawData('General');
1389 1
        $objWriter->endElement();
1390
1391 1
        $objWriter->startElement('c:ptCount');
1392 1
        $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount());
1393 1
        $objWriter->endElement();
1394
1395 1
        $dataValues = $plotSeriesValues->getDataValues();
1396 1
        if (!empty($dataValues)) {
1397 1
            if (is_array($dataValues)) {
1398 1
                foreach ($dataValues as $plotSeriesKey => $plotSeriesValue) {
1399 1
                    $objWriter->startElement('c:pt');
1400 1
                    $objWriter->writeAttribute('idx', $plotSeriesKey);
1401 1
                    $objWriter->startElement('c:v');
1402 1
                    $objWriter->writeRawData(1);
1403 1
                    $objWriter->endElement();
1404 1
                    $objWriter->endElement();
1405
                }
1406
            }
1407
        }
1408
1409 1
        $objWriter->endElement();
1410 1
        $objWriter->endElement();
1411
1412 1
        $objWriter->startElement('c:bubble3D');
1413 1
        $objWriter->writeAttribute('val', 0);
1414 1
        $objWriter->endElement();
1415 1
    }
1416
1417
    /**
1418
     * Write Layout.
1419
     *
1420
     * @param XMLWriter $objWriter XML Writer
1421
     * @param Layout $layout
1422
     *
1423
     * @throws WriterException
1424
     */
1425 13
    private function writeLayout(XMLWriter $objWriter, Layout $layout = null)
1426
    {
1427 13
        $objWriter->startElement('c:layout');
1428
1429 13
        if (!is_null($layout)) {
1430 3
            $objWriter->startElement('c:manualLayout');
1431
1432 3
            $layoutTarget = $layout->getLayoutTarget();
1433 3
            if (!is_null($layoutTarget)) {
1434 1
                $objWriter->startElement('c:layoutTarget');
1435 1
                $objWriter->writeAttribute('val', $layoutTarget);
1436 1
                $objWriter->endElement();
1437
            }
1438
1439 3
            $xMode = $layout->getXMode();
1440 3
            if (!is_null($xMode)) {
1441 1
                $objWriter->startElement('c:xMode');
1442 1
                $objWriter->writeAttribute('val', $xMode);
1443 1
                $objWriter->endElement();
1444
            }
1445
1446 3
            $yMode = $layout->getYMode();
1447 3
            if (!is_null($yMode)) {
1448 1
                $objWriter->startElement('c:yMode');
1449 1
                $objWriter->writeAttribute('val', $yMode);
1450 1
                $objWriter->endElement();
1451
            }
1452
1453 3
            $x = $layout->getXPosition();
1454 3
            if (!is_null($x)) {
1455 1
                $objWriter->startElement('c:x');
1456 1
                $objWriter->writeAttribute('val', $x);
1457 1
                $objWriter->endElement();
1458
            }
1459
1460 3
            $y = $layout->getYPosition();
1461 3
            if (!is_null($y)) {
1462 1
                $objWriter->startElement('c:y');
1463 1
                $objWriter->writeAttribute('val', $y);
1464 1
                $objWriter->endElement();
1465
            }
1466
1467 3
            $w = $layout->getWidth();
1468 3
            if (!is_null($w)) {
1469 1
                $objWriter->startElement('c:w');
1470 1
                $objWriter->writeAttribute('val', $w);
1471 1
                $objWriter->endElement();
1472
            }
1473
1474 3
            $h = $layout->getHeight();
1475 3
            if (!is_null($h)) {
1476 1
                $objWriter->startElement('c:h');
1477 1
                $objWriter->writeAttribute('val', $h);
1478 1
                $objWriter->endElement();
1479
            }
1480
1481 3
            $objWriter->endElement();
1482
        }
1483
1484 13
        $objWriter->endElement();
1485 13
    }
1486
1487
    /**
1488
     * Write Alternate Content block.
1489
     *
1490
     * @param XMLWriter $objWriter XML Writer
1491
     *
1492
     * @throws WriterException
1493
     */
1494 13
    private function writeAlternateContent($objWriter)
1495
    {
1496 13
        $objWriter->startElement('mc:AlternateContent');
1497 13
        $objWriter->writeAttribute('xmlns:mc', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
1498
1499 13
        $objWriter->startElement('mc:Choice');
1500 13
        $objWriter->writeAttribute('xmlns:c14', 'http://schemas.microsoft.com/office/drawing/2007/8/2/chart');
1501 13
        $objWriter->writeAttribute('Requires', 'c14');
1502
1503 13
        $objWriter->startElement('c14:style');
1504 13
        $objWriter->writeAttribute('val', '102');
1505 13
        $objWriter->endElement();
1506 13
        $objWriter->endElement();
1507
1508 13
        $objWriter->startElement('mc:Fallback');
1509 13
        $objWriter->startElement('c:style');
1510 13
        $objWriter->writeAttribute('val', '2');
1511 13
        $objWriter->endElement();
1512 13
        $objWriter->endElement();
1513
1514 13
        $objWriter->endElement();
1515 13
    }
1516
1517
    /**
1518
     * Write Printer Settings.
1519
     *
1520
     * @param XMLWriter $objWriter XML Writer
1521
     *
1522
     * @throws WriterException
1523
     */
1524 13
    private function writePrintSettings($objWriter)
1525
    {
1526 13
        $objWriter->startElement('c:printSettings');
1527
1528 13
        $objWriter->startElement('c:headerFooter');
1529 13
        $objWriter->endElement();
1530
1531 13
        $objWriter->startElement('c:pageMargins');
1532 13
        $objWriter->writeAttribute('footer', 0.3);
1533 13
        $objWriter->writeAttribute('header', 0.3);
1534 13
        $objWriter->writeAttribute('r', 0.7);
1535 13
        $objWriter->writeAttribute('l', 0.7);
1536 13
        $objWriter->writeAttribute('t', 0.75);
1537 13
        $objWriter->writeAttribute('b', 0.75);
1538 13
        $objWriter->endElement();
1539
1540 13
        $objWriter->startElement('c:pageSetup');
1541 13
        $objWriter->writeAttribute('orientation', 'portrait');
1542 13
        $objWriter->endElement();
1543
1544 13
        $objWriter->endElement();
1545 13
    }
1546
}
1547