Completed
Push — develop ( 75d3bd...a06533 )
by Adrien
21:48
created

Chart::writePrintSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 1
dl 0
loc 22
ccs 17
cts 17
cp 1
crap 1
rs 9.2
c 0
b 0
f 0
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
14
/**
15
 * Copyright (c) 2006 - 2016 PhpSpreadsheet.
16
 *
17
 * This library is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU Lesser General Public
19
 * License as published by the Free Software Foundation; either
20
 * version 2.1 of the License, or (at your option) any later version.
21
 *
22
 * This library is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
 * Lesser General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU Lesser General Public
28
 * License along with this library; if not, write to the Free Software
29
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30
 *
31
 * @category   PhpSpreadsheet
32
 *
33
 * @copyright  Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
34
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
35
 */
36
class Chart extends WriterPart
37
{
38
    protected $calculateCellValues;
39
40
    /**
41
     * Write charts to XML format.
42
     *
43
     * @param \PhpOffice\PhpSpreadsheet\Chart $pChart
44
     * @param mixed $calculateCellValues
45
     *
46
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
47
     *
48
     * @return string XML Output
49
     */
50 13
    public function writeChart(\PhpOffice\PhpSpreadsheet\Chart $pChart, $calculateCellValues = true)
51
    {
52 13
        $this->calculateCellValues = $calculateCellValues;
53
54
        // Create XML writer
55 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...
56 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...
Bug introduced by
It seems like you code against a concrete implementation and not the interface PhpOffice\PhpSpreadsheet\Writer\IWriter as the method getUseDiskCaching() does only exist in the following implementations of said interface: PhpOffice\PhpSpreadsheet\Writer\BaseWriter, PhpOffice\PhpSpreadsheet\Writer\Csv, PhpOffice\PhpSpreadsheet\Writer\Html, PhpOffice\PhpSpreadsheet\Writer\Ods, PhpOffice\PhpSpreadsheet\Writer\Pdf\Core, PhpOffice\PhpSpreadsheet\Writer\Pdf\DomPDF, PhpOffice\PhpSpreadsheet\Writer\Pdf\MPDF, PhpOffice\PhpSpreadsheet\Writer\Pdf\TcPDF, PhpOffice\PhpSpreadsheet\Writer\Xls, PhpOffice\PhpSpreadsheet\Writer\Xlsx.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
57
            $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface PhpOffice\PhpSpreadsheet\Writer\IWriter as the method getDiskCachingDirectory() does only exist in the following implementations of said interface: PhpOffice\PhpSpreadsheet\Writer\BaseWriter, PhpOffice\PhpSpreadsheet\Writer\Csv, PhpOffice\PhpSpreadsheet\Writer\Html, PhpOffice\PhpSpreadsheet\Writer\Ods, PhpOffice\PhpSpreadsheet\Writer\Pdf\Core, PhpOffice\PhpSpreadsheet\Writer\Pdf\DomPDF, PhpOffice\PhpSpreadsheet\Writer\Pdf\MPDF, PhpOffice\PhpSpreadsheet\Writer\Pdf\TcPDF, PhpOffice\PhpSpreadsheet\Writer\Xls, PhpOffice\PhpSpreadsheet\Writer\Xlsx.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

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

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
152
153 13
        $objWriter->endElement();
154 13
        $objWriter->endElement();
155 13
        $objWriter->endElement();
156
157 13
        $this->writeLayout($objWriter, $title->getLayout());
158
159 13
        $objWriter->startElement('c:overlay');
160 13
        $objWriter->writeAttribute('val', 0);
161 13
        $objWriter->endElement();
162
163 13
        $objWriter->endElement();
164 13
    }
165
166
    /**
167
     * Write Chart Legend.
168
     *
169
     * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
170
     * @param Legend $legend
171
     *
172
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
173
     */
174 13
    private function writeLegend(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, Legend $legend = null)
175
    {
176 13
        if (is_null($legend)) {
177 2
            return;
178
        }
179
180 13
        $objWriter->startElement('c:legend');
181
182 13
        $objWriter->startElement('c:legendPos');
183 13
        $objWriter->writeAttribute('val', $legend->getPosition());
184 13
        $objWriter->endElement();
185
186 13
        $this->writeLayout($objWriter, $legend->getLayout());
187
188 13
        $objWriter->startElement('c:overlay');
189 13
        $objWriter->writeAttribute('val', ($legend->getOverlay()) ? '1' : '0');
190 13
        $objWriter->endElement();
191
192 13
        $objWriter->startElement('c:txPr');
193 13
        $objWriter->startElement('a:bodyPr');
194 13
        $objWriter->endElement();
195
196 13
        $objWriter->startElement('a:lstStyle');
197 13
        $objWriter->endElement();
198
199 13
        $objWriter->startElement('a:p');
200 13
        $objWriter->startElement('a:pPr');
201 13
        $objWriter->writeAttribute('rtl', 0);
202
203 13
        $objWriter->startElement('a:defRPr');
204 13
        $objWriter->endElement();
205 13
        $objWriter->endElement();
206
207 13
        $objWriter->startElement('a:endParaRPr');
208 13
        $objWriter->writeAttribute('lang', 'en-US');
209 13
        $objWriter->endElement();
210
211 13
        $objWriter->endElement();
212 13
        $objWriter->endElement();
213
214 13
        $objWriter->endElement();
215 13
    }
216
217
    /**
218
     * Write Chart Plot Area.
219
     *
220
     * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
221
     * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet
222
     * @param PlotArea $plotArea
223
     * @param Title $xAxisLabel
224
     * @param Title $yAxisLabel
225
     * @param Axis $xAxis
226
     * @param Axis $yAxis
227
     *
228
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
229
     */
230 13
    private function writePlotArea(\PhpOffice\PhpSpreadsheet\Shared\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)
231
    {
232 13
        if (is_null($plotArea)) {
233
            return;
234
        }
235
236 13
        $id1 = $id2 = 0;
237 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...
238 13
        $objWriter->startElement('c:plotArea');
239
240 13
        $layout = $plotArea->getLayout();
241
242 13
        $this->writeLayout($objWriter, $layout);
243
244 13
        $chartTypes = self::getChartType($plotArea);
245 13
        $catIsMultiLevelSeries = $valIsMultiLevelSeries = false;
246 13
        $plotGroupingType = '';
247 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...
248 13
            $objWriter->startElement('c:' . $chartType);
249
250 13
            $groupCount = $plotArea->getPlotGroupCount();
251 13
            for ($i = 0; $i < $groupCount; ++$i) {
252 13
                $plotGroup = $plotArea->getPlotGroupByIndex($i);
253 13
                $groupType = $plotGroup->getPlotType();
254 13
                if ($groupType == $chartType) {
255 13
                    $plotStyle = $plotGroup->getPlotStyle();
256 13
                    if ($groupType === DataSeries::TYPE_RADARCHART) {
257 2
                        $objWriter->startElement('c:radarStyle');
258 2
                        $objWriter->writeAttribute('val', $plotStyle);
259 2
                        $objWriter->endElement();
260 12
                    } elseif ($groupType === DataSeries::TYPE_SCATTERCHART) {
261 2
                        $objWriter->startElement('c:scatterStyle');
262 2
                        $objWriter->writeAttribute('val', $plotStyle);
263 2
                        $objWriter->endElement();
264
                    }
265
266 13
                    $this->writePlotGroup($plotGroup, $chartType, $objWriter, $catIsMultiLevelSeries, $valIsMultiLevelSeries, $plotGroupingType, $pSheet);
267
                }
268
            }
269
270 13
            $this->writeDataLabels($objWriter, $layout);
271
272 13
            if ($chartType === DataSeries::TYPE_LINECHART) {
273
                //    Line only, Line3D can't be smoothed
274 3
                $objWriter->startElement('c:smooth');
275 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...
276 3
                $objWriter->endElement();
277 12
            } elseif (($chartType === DataSeries::TYPE_BARCHART) || ($chartType === DataSeries::TYPE_BARCHART_3D)) {
278 7
                $objWriter->startElement('c:gapWidth');
279 7
                $objWriter->writeAttribute('val', 150);
280 7
                $objWriter->endElement();
281
282 7
                if ($plotGroupingType == 'percentStacked' || $plotGroupingType == 'stacked') {
283 2
                    $objWriter->startElement('c:overlap');
284 2
                    $objWriter->writeAttribute('val', 100);
285 2
                    $objWriter->endElement();
286
                }
287 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...
288 1
                $objWriter->startElement('c:bubbleScale');
289 1
                $objWriter->writeAttribute('val', 25);
290 1
                $objWriter->endElement();
291
292 1
                $objWriter->startElement('c:showNegBubbles');
293 1
                $objWriter->writeAttribute('val', 0);
294 1
                $objWriter->endElement();
295 8
            } elseif ($chartType === DataSeries::TYPE_STOCKCHART) {
296 2
                $objWriter->startElement('c:hiLowLines');
297 2
                $objWriter->endElement();
298
299 2
                $objWriter->startElement('c:upDownBars');
300
301 2
                $objWriter->startElement('c:gapWidth');
302 2
                $objWriter->writeAttribute('val', 300);
303 2
                $objWriter->endElement();
304
305 2
                $objWriter->startElement('c:upBars');
306 2
                $objWriter->endElement();
307
308 2
                $objWriter->startElement('c:downBars');
309 2
                $objWriter->endElement();
310
311 2
                $objWriter->endElement();
312
            }
313
314
            //    Generate 2 unique numbers to use for axId values
315 13
            $id1 = '75091328';
316 13
            $id2 = '75089408';
317
318 13
            if (($chartType !== DataSeries::TYPE_PIECHART) && ($chartType !== DataSeries::TYPE_PIECHART_3D) && ($chartType !== DataSeries::TYPE_DONUTCHART)) {
319 12
                $objWriter->startElement('c:axId');
320 12
                $objWriter->writeAttribute('val', $id1);
321 12
                $objWriter->endElement();
322 12
                $objWriter->startElement('c:axId');
323 12
                $objWriter->writeAttribute('val', $id2);
324 12
                $objWriter->endElement();
325 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...
326 2
                $objWriter->startElement('c:firstSliceAng');
327 2
                $objWriter->writeAttribute('val', 0);
328 2
                $objWriter->endElement();
329
330 2
                if ($chartType === DataSeries::TYPE_DONUTCHART) {
331 2
                    $objWriter->startElement('c:holeSize');
332 2
                    $objWriter->writeAttribute('val', 50);
333 2
                    $objWriter->endElement();
334
                }
335
            }
336
337 13
            $objWriter->endElement();
338
        }
339
340 13
        if (($chartType !== DataSeries::TYPE_PIECHART) && ($chartType !== DataSeries::TYPE_PIECHART_3D) && ($chartType !== DataSeries::TYPE_DONUTCHART)) {
341 12
            if ($chartType === DataSeries::TYPE_BUBBLECHART) {
342 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 247. 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 230 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...
343
            } else {
344 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 230 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...
345
            }
346
347 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 230 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...
348
        }
349
350 13
        $objWriter->endElement();
351 13
    }
352
353
    /**
354
     * Write Data Labels.
355
     *
356
     * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
357
     * @param \PhpOffice\PhpSpreadsheet\Chart\Layout $chartLayout Chart layout
358
     *
359
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
360
     */
361 13
    private function writeDataLabels(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, Layout $chartLayout = null)
362
    {
363 13
        $objWriter->startElement('c:dLbls');
364
365 13
        $objWriter->startElement('c:showLegendKey');
366 13
        $showLegendKey = (empty($chartLayout)) ? 0 : $chartLayout->getShowLegendKey();
367 13
        $objWriter->writeAttribute('val', ((empty($showLegendKey)) ? 0 : 1));
368 13
        $objWriter->endElement();
369
370 13
        $objWriter->startElement('c:showVal');
371 13
        $showVal = (empty($chartLayout)) ? 0 : $chartLayout->getShowVal();
372 13
        $objWriter->writeAttribute('val', ((empty($showVal)) ? 0 : 1));
373 13
        $objWriter->endElement();
374
375 13
        $objWriter->startElement('c:showCatName');
376 13
        $showCatName = (empty($chartLayout)) ? 0 : $chartLayout->getShowCatName();
377 13
        $objWriter->writeAttribute('val', ((empty($showCatName)) ? 0 : 1));
378 13
        $objWriter->endElement();
379
380 13
        $objWriter->startElement('c:showSerName');
381 13
        $showSerName = (empty($chartLayout)) ? 0 : $chartLayout->getShowSerName();
382 13
        $objWriter->writeAttribute('val', ((empty($showSerName)) ? 0 : 1));
383 13
        $objWriter->endElement();
384
385 13
        $objWriter->startElement('c:showPercent');
386 13
        $showPercent = (empty($chartLayout)) ? 0 : $chartLayout->getShowPercent();
387 13
        $objWriter->writeAttribute('val', ((empty($showPercent)) ? 0 : 1));
388 13
        $objWriter->endElement();
389
390 13
        $objWriter->startElement('c:showBubbleSize');
391 13
        $showBubbleSize = (empty($chartLayout)) ? 0 : $chartLayout->getShowBubbleSize();
392 13
        $objWriter->writeAttribute('val', ((empty($showBubbleSize)) ? 0 : 1));
393 13
        $objWriter->endElement();
394
395 13
        $objWriter->startElement('c:showLeaderLines');
396 13
        $showLeaderLines = (empty($chartLayout)) ? 1 : $chartLayout->getShowLeaderLines();
397 13
        $objWriter->writeAttribute('val', ((empty($showLeaderLines)) ? 0 : 1));
398 13
        $objWriter->endElement();
399
400 13
        $objWriter->endElement();
401 13
    }
402
403
    /**
404
     * Write Category Axis.
405
     *
406
     * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
407
     * @param PlotArea $plotArea
408
     * @param Title $xAxisLabel
409
     * @param string $groupType Chart type
410
     * @param string $id1
411
     * @param string $id2
412
     * @param bool $isMultiLevelSeries
413
     * @param mixed $xAxis
414
     * @param mixed $yAxis
415
     *
416
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
417
     */
418 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...
419
    {
420 12
        $objWriter->startElement('c:catAx');
421
422 12
        if ($id1 > 0) {
423 12
            $objWriter->startElement('c:axId');
424 12
            $objWriter->writeAttribute('val', $id1);
425 12
            $objWriter->endElement();
426
        }
427
428 12
        $objWriter->startElement('c:scaling');
429 12
        $objWriter->startElement('c:orientation');
430 12
        $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('orientation'));
431 12
        $objWriter->endElement();
432 12
        $objWriter->endElement();
433
434 12
        $objWriter->startElement('c:delete');
435 12
        $objWriter->writeAttribute('val', 0);
436 12
        $objWriter->endElement();
437
438 12
        $objWriter->startElement('c:axPos');
439 12
        $objWriter->writeAttribute('val', 'b');
440 12
        $objWriter->endElement();
441
442 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...
443 3
            $objWriter->startElement('c:title');
444 3
            $objWriter->startElement('c:tx');
445 3
            $objWriter->startElement('c:rich');
446
447 3
            $objWriter->startElement('a:bodyPr');
448 3
            $objWriter->endElement();
449
450 3
            $objWriter->startElement('a:lstStyle');
451 3
            $objWriter->endElement();
452
453 3
            $objWriter->startElement('a:p');
454 3
            $objWriter->startElement('a:r');
455
456 3
            $caption = $xAxisLabel->getCaption();
457 3
            if (is_array($caption)) {
458 1
                $caption = $caption[0];
459
            }
460 3
            $objWriter->startElement('a:t');
461 3
            $objWriter->writeRawData(\PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterPHP2OOXML($caption));
462 3
            $objWriter->endElement();
463
464 3
            $objWriter->endElement();
465 3
            $objWriter->endElement();
466 3
            $objWriter->endElement();
467 3
            $objWriter->endElement();
468
469 3
            $layout = $xAxisLabel->getLayout();
470 3
            $this->writeLayout($objWriter, $layout);
471
472 3
            $objWriter->startElement('c:overlay');
473 3
            $objWriter->writeAttribute('val', 0);
474 3
            $objWriter->endElement();
475
476 3
            $objWriter->endElement();
477
        }
478
479 12
        $objWriter->startElement('c:numFmt');
480 12
        $objWriter->writeAttribute('formatCode', $yAxis->getAxisNumberFormat());
481 12
        $objWriter->writeAttribute('sourceLinked', $yAxis->getAxisNumberSourceLinked());
482 12
        $objWriter->endElement();
483
484 12
        $objWriter->startElement('c:majorTickMark');
485 12
        $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('major_tick_mark'));
486 12
        $objWriter->endElement();
487
488 12
        $objWriter->startElement('c:minorTickMark');
489 12
        $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('minor_tick_mark'));
490 12
        $objWriter->endElement();
491
492 12
        $objWriter->startElement('c:tickLblPos');
493 12
        $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('axis_labels'));
494 12
        $objWriter->endElement();
495
496 12
        if ($id2 > 0) {
497 12
            $objWriter->startElement('c:crossAx');
498 12
            $objWriter->writeAttribute('val', $id2);
499 12
            $objWriter->endElement();
500
501 12
            $objWriter->startElement('c:crosses');
502 12
            $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('horizontal_crosses'));
503 12
            $objWriter->endElement();
504
        }
505
506 12
        $objWriter->startElement('c:auto');
507 12
        $objWriter->writeAttribute('val', 1);
508 12
        $objWriter->endElement();
509
510 12
        $objWriter->startElement('c:lblAlgn');
511 12
        $objWriter->writeAttribute('val', 'ctr');
512 12
        $objWriter->endElement();
513
514 12
        $objWriter->startElement('c:lblOffset');
515 12
        $objWriter->writeAttribute('val', 100);
516 12
        $objWriter->endElement();
517
518 12
        if ($isMultiLevelSeries) {
519 2
            $objWriter->startElement('c:noMultiLvlLbl');
520 2
            $objWriter->writeAttribute('val', 0);
521 2
            $objWriter->endElement();
522
        }
523 12
        $objWriter->endElement();
524 12
    }
525
526
    /**
527
     * Write Value Axis.
528
     *
529
     * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
530
     * @param PlotArea $plotArea
531
     * @param Title $yAxisLabel
532
     * @param string $groupType Chart type
533
     * @param string $id1
534
     * @param string $id2
535
     * @param bool $isMultiLevelSeries
536
     * @param mixed $xAxis
537
     * @param mixed $yAxis
538
     * @param mixed $majorGridlines
539
     * @param mixed $minorGridlines
540
     *
541
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
542
     */
543 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...
544
    {
545 12
        $objWriter->startElement('c:valAx');
546
547 12
        if ($id2 > 0) {
548 12
            $objWriter->startElement('c:axId');
549 12
            $objWriter->writeAttribute('val', $id2);
550 12
            $objWriter->endElement();
551
        }
552
553 12
        $objWriter->startElement('c:scaling');
554
555 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...
556
            $objWriter->startElement('c:max');
557
            $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('maximum'));
558
            $objWriter->endElement();
559
        }
560
561 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...
562
            $objWriter->startElement('c:min');
563
            $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minimum'));
564
            $objWriter->endElement();
565
        }
566
567 12
        $objWriter->startElement('c:orientation');
568 12
        $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('orientation'));
569
570 12
        $objWriter->endElement();
571 12
        $objWriter->endElement();
572
573 12
        $objWriter->startElement('c:delete');
574 12
        $objWriter->writeAttribute('val', 0);
575 12
        $objWriter->endElement();
576
577 12
        $objWriter->startElement('c:axPos');
578 12
        $objWriter->writeAttribute('val', 'l');
579 12
        $objWriter->endElement();
580
581 12
        $objWriter->startElement('c:majorGridlines');
582 12
        $objWriter->startElement('c:spPr');
583
584 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...
585
            $objWriter->startElement('a:ln');
586
            $objWriter->writeAttribute('w', $majorGridlines->getLineStyleProperty('width'));
587
            $objWriter->startElement('a:solidFill');
588
            $objWriter->startElement("a:{$majorGridlines->getLineColorProperty('type')}");
589
            $objWriter->writeAttribute('val', $majorGridlines->getLineColorProperty('value'));
590
            $objWriter->startElement('a:alpha');
591
            $objWriter->writeAttribute('val', $majorGridlines->getLineColorProperty('alpha'));
592
            $objWriter->endElement(); //end alpha
593
            $objWriter->endElement(); //end srgbClr
594
            $objWriter->endElement(); //end solidFill
595
596
            $objWriter->startElement('a:prstDash');
597
            $objWriter->writeAttribute('val', $majorGridlines->getLineStyleProperty('dash'));
598
            $objWriter->endElement();
599
600
            if ($majorGridlines->getLineStyleProperty('join') == 'miter') {
601
                $objWriter->startElement('a:miter');
602
                $objWriter->writeAttribute('lim', '800000');
603
                $objWriter->endElement();
604
            } else {
605
                $objWriter->startElement('a:bevel');
606
                $objWriter->endElement();
607
            }
608
609
            if (!is_null($majorGridlines->getLineStyleProperty(['arrow', 'head', 'type']))) {
610
                $objWriter->startElement('a:headEnd');
611
                $objWriter->writeAttribute('type', $majorGridlines->getLineStyleProperty(['arrow', 'head', 'type']));
612
                $objWriter->writeAttribute('w', $majorGridlines->getLineStyleArrowParameters('head', 'w'));
613
                $objWriter->writeAttribute('len', $majorGridlines->getLineStyleArrowParameters('head', 'len'));
614
                $objWriter->endElement();
615
            }
616
617
            if (!is_null($majorGridlines->getLineStyleProperty(['arrow', 'end', 'type']))) {
618
                $objWriter->startElement('a:tailEnd');
619
                $objWriter->writeAttribute('type', $majorGridlines->getLineStyleProperty(['arrow', 'end', 'type']));
620
                $objWriter->writeAttribute('w', $majorGridlines->getLineStyleArrowParameters('end', 'w'));
621
                $objWriter->writeAttribute('len', $majorGridlines->getLineStyleArrowParameters('end', 'len'));
622
                $objWriter->endElement();
623
            }
624
            $objWriter->endElement(); //end ln
625
        }
626 12
        $objWriter->startElement('a:effectLst');
627
628 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...
629
            $objWriter->startElement('a:glow');
630
            $objWriter->writeAttribute('rad', $majorGridlines->getGlowSize());
631
            $objWriter->startElement("a:{$majorGridlines->getGlowColor('type')}");
632
            $objWriter->writeAttribute('val', $majorGridlines->getGlowColor('value'));
633
            $objWriter->startElement('a:alpha');
634
            $objWriter->writeAttribute('val', $majorGridlines->getGlowColor('alpha'));
635
            $objWriter->endElement(); //end alpha
636
            $objWriter->endElement(); //end schemeClr
637
            $objWriter->endElement(); //end glow
638
        }
639
640 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...
641
            $objWriter->startElement("a:{$majorGridlines->getShadowProperty('effect')}");
642
            if (!is_null($majorGridlines->getShadowProperty('blur'))) {
643
                $objWriter->writeAttribute('blurRad', $majorGridlines->getShadowProperty('blur'));
644
            }
645
            if (!is_null($majorGridlines->getShadowProperty('distance'))) {
646
                $objWriter->writeAttribute('dist', $majorGridlines->getShadowProperty('distance'));
647
            }
648
            if (!is_null($majorGridlines->getShadowProperty('direction'))) {
649
                $objWriter->writeAttribute('dir', $majorGridlines->getShadowProperty('direction'));
650
            }
651
            if (!is_null($majorGridlines->getShadowProperty('algn'))) {
652
                $objWriter->writeAttribute('algn', $majorGridlines->getShadowProperty('algn'));
653
            }
654
            if (!is_null($majorGridlines->getShadowProperty(['size', 'sx']))) {
655
                $objWriter->writeAttribute('sx', $majorGridlines->getShadowProperty(['size', 'sx']));
656
            }
657
            if (!is_null($majorGridlines->getShadowProperty(['size', 'sy']))) {
658
                $objWriter->writeAttribute('sy', $majorGridlines->getShadowProperty(['size', 'sy']));
659
            }
660
            if (!is_null($majorGridlines->getShadowProperty(['size', 'kx']))) {
661
                $objWriter->writeAttribute('kx', $majorGridlines->getShadowProperty(['size', 'kx']));
662
            }
663
            if (!is_null($majorGridlines->getShadowProperty('rotWithShape'))) {
664
                $objWriter->writeAttribute('rotWithShape', $majorGridlines->getShadowProperty('rotWithShape'));
665
            }
666
            $objWriter->startElement("a:{$majorGridlines->getShadowProperty(['color', 'type'])}");
667
            $objWriter->writeAttribute('val', $majorGridlines->getShadowProperty(['color', 'value']));
668
669
            $objWriter->startElement('a:alpha');
670
            $objWriter->writeAttribute('val', $majorGridlines->getShadowProperty(['color', 'alpha']));
671
            $objWriter->endElement(); //end alpha
672
673
            $objWriter->endElement(); //end color:type
674
            $objWriter->endElement(); //end shadow
675
        }
676
677 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...
678
            $objWriter->startElement('a:softEdge');
679
            $objWriter->writeAttribute('rad', $majorGridlines->getSoftEdgesSize());
680
            $objWriter->endElement(); //end softEdge
681
        }
682
683 12
        $objWriter->endElement(); //end effectLst
684 12
        $objWriter->endElement(); //end spPr
685 12
        $objWriter->endElement(); //end majorGridLines
686
687 12
        if ($minorGridlines->getObjectState()) {
688
            $objWriter->startElement('c:minorGridlines');
689
            $objWriter->startElement('c:spPr');
690
691 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...
692
                $objWriter->startElement('a:ln');
693
                $objWriter->writeAttribute('w', $minorGridlines->getLineStyleProperty('width'));
694
                $objWriter->startElement('a:solidFill');
695
                $objWriter->startElement("a:{$minorGridlines->getLineColorProperty('type')}");
696
                $objWriter->writeAttribute('val', $minorGridlines->getLineColorProperty('value'));
697
                $objWriter->startElement('a:alpha');
698
                $objWriter->writeAttribute('val', $minorGridlines->getLineColorProperty('alpha'));
699
                $objWriter->endElement(); //end alpha
700
                $objWriter->endElement(); //end srgbClr
701
                $objWriter->endElement(); //end solidFill
702
703
                $objWriter->startElement('a:prstDash');
704
                $objWriter->writeAttribute('val', $minorGridlines->getLineStyleProperty('dash'));
705
                $objWriter->endElement();
706
707
                if ($minorGridlines->getLineStyleProperty('join') == 'miter') {
708
                    $objWriter->startElement('a:miter');
709
                    $objWriter->writeAttribute('lim', '800000');
710
                    $objWriter->endElement();
711
                } else {
712
                    $objWriter->startElement('a:bevel');
713
                    $objWriter->endElement();
714
                }
715
716
                if (!is_null($minorGridlines->getLineStyleProperty(['arrow', 'head', 'type']))) {
717
                    $objWriter->startElement('a:headEnd');
718
                    $objWriter->writeAttribute('type', $minorGridlines->getLineStyleProperty(['arrow', 'head', 'type']));
719
                    $objWriter->writeAttribute('w', $minorGridlines->getLineStyleArrowParameters('head', 'w'));
720
                    $objWriter->writeAttribute('len', $minorGridlines->getLineStyleArrowParameters('head', 'len'));
721
                    $objWriter->endElement();
722
                }
723
724
                if (!is_null($minorGridlines->getLineStyleProperty(['arrow', 'end', 'type']))) {
725
                    $objWriter->startElement('a:tailEnd');
726
                    $objWriter->writeAttribute('type', $minorGridlines->getLineStyleProperty(['arrow', 'end', 'type']));
727
                    $objWriter->writeAttribute('w', $minorGridlines->getLineStyleArrowParameters('end', 'w'));
728
                    $objWriter->writeAttribute('len', $minorGridlines->getLineStyleArrowParameters('end', 'len'));
729
                    $objWriter->endElement();
730
                }
731
                $objWriter->endElement(); //end ln
732
            }
733
734
            $objWriter->startElement('a:effectLst');
735
736 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...
737
                $objWriter->startElement('a:glow');
738
                $objWriter->writeAttribute('rad', $minorGridlines->getGlowSize());
739
                $objWriter->startElement("a:{$minorGridlines->getGlowColor('type')}");
740
                $objWriter->writeAttribute('val', $minorGridlines->getGlowColor('value'));
741
                $objWriter->startElement('a:alpha');
742
                $objWriter->writeAttribute('val', $minorGridlines->getGlowColor('alpha'));
743
                $objWriter->endElement(); //end alpha
744
                $objWriter->endElement(); //end schemeClr
745
                $objWriter->endElement(); //end glow
746
            }
747
748 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...
749
                $objWriter->startElement("a:{$minorGridlines->getShadowProperty('effect')}");
750
                if (!is_null($minorGridlines->getShadowProperty('blur'))) {
751
                    $objWriter->writeAttribute('blurRad', $minorGridlines->getShadowProperty('blur'));
752
                }
753
                if (!is_null($minorGridlines->getShadowProperty('distance'))) {
754
                    $objWriter->writeAttribute('dist', $minorGridlines->getShadowProperty('distance'));
755
                }
756
                if (!is_null($minorGridlines->getShadowProperty('direction'))) {
757
                    $objWriter->writeAttribute('dir', $minorGridlines->getShadowProperty('direction'));
758
                }
759
                if (!is_null($minorGridlines->getShadowProperty('algn'))) {
760
                    $objWriter->writeAttribute('algn', $minorGridlines->getShadowProperty('algn'));
761
                }
762
                if (!is_null($minorGridlines->getShadowProperty(['size', 'sx']))) {
763
                    $objWriter->writeAttribute('sx', $minorGridlines->getShadowProperty(['size', 'sx']));
764
                }
765
                if (!is_null($minorGridlines->getShadowProperty(['size', 'sy']))) {
766
                    $objWriter->writeAttribute('sy', $minorGridlines->getShadowProperty(['size', 'sy']));
767
                }
768
                if (!is_null($minorGridlines->getShadowProperty(['size', 'kx']))) {
769
                    $objWriter->writeAttribute('kx', $minorGridlines->getShadowProperty(['size', 'kx']));
770
                }
771
                if (!is_null($minorGridlines->getShadowProperty('rotWithShape'))) {
772
                    $objWriter->writeAttribute('rotWithShape', $minorGridlines->getShadowProperty('rotWithShape'));
773
                }
774
                $objWriter->startElement("a:{$minorGridlines->getShadowProperty(['color', 'type'])}");
775
                $objWriter->writeAttribute('val', $minorGridlines->getShadowProperty(['color', 'value']));
776
                $objWriter->startElement('a:alpha');
777
                $objWriter->writeAttribute('val', $minorGridlines->getShadowProperty(['color', 'alpha']));
778
                $objWriter->endElement(); //end alpha
779
                $objWriter->endElement(); //end color:type
780
                $objWriter->endElement(); //end shadow
781
            }
782
783 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...
784
                $objWriter->startElement('a:softEdge');
785
                $objWriter->writeAttribute('rad', $minorGridlines->getSoftEdgesSize());
786
                $objWriter->endElement(); //end softEdge
787
            }
788
789
            $objWriter->endElement(); //end effectLst
790
            $objWriter->endElement(); //end spPr
791
            $objWriter->endElement(); //end minorGridLines
792
        }
793
794 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...
795 10
            $objWriter->startElement('c:title');
796 10
            $objWriter->startElement('c:tx');
797 10
            $objWriter->startElement('c:rich');
798
799 10
            $objWriter->startElement('a:bodyPr');
800 10
            $objWriter->endElement();
801
802 10
            $objWriter->startElement('a:lstStyle');
803 10
            $objWriter->endElement();
804
805 10
            $objWriter->startElement('a:p');
806 10
            $objWriter->startElement('a:r');
807
808 10
            $caption = $yAxisLabel->getCaption();
809 10
            if (is_array($caption)) {
810 1
                $caption = $caption[0];
811
            }
812
813 10
            $objWriter->startElement('a:t');
814 10
            $objWriter->writeRawData(\PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterPHP2OOXML($caption));
815 10
            $objWriter->endElement();
816
817 10
            $objWriter->endElement();
818 10
            $objWriter->endElement();
819 10
            $objWriter->endElement();
820 10
            $objWriter->endElement();
821
822 10
            if ($groupType !== DataSeries::TYPE_BUBBLECHART) {
823 10
                $layout = $yAxisLabel->getLayout();
824 10
                $this->writeLayout($objWriter, $layout);
825
            }
826
827 10
            $objWriter->startElement('c:overlay');
828 10
            $objWriter->writeAttribute('val', 0);
829 10
            $objWriter->endElement();
830
831 10
            $objWriter->endElement();
832
        }
833
834 12
        $objWriter->startElement('c:numFmt');
835 12
        $objWriter->writeAttribute('formatCode', $xAxis->getAxisNumberFormat());
836 12
        $objWriter->writeAttribute('sourceLinked', $xAxis->getAxisNumberSourceLinked());
837 12
        $objWriter->endElement();
838
839 12
        $objWriter->startElement('c:majorTickMark');
840 12
        $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('major_tick_mark'));
841 12
        $objWriter->endElement();
842
843 12
        $objWriter->startElement('c:minorTickMark');
844 12
        $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minor_tick_mark'));
845 12
        $objWriter->endElement();
846
847 12
        $objWriter->startElement('c:tickLblPos');
848 12
        $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('axis_labels'));
849 12
        $objWriter->endElement();
850
851 12
        $objWriter->startElement('c:spPr');
852
853 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...
854
            $objWriter->startElement('a:solidFill');
855
            $objWriter->startElement('a:' . $xAxis->getFillProperty('type'));
856
            $objWriter->writeAttribute('val', $xAxis->getFillProperty('value'));
857
            $objWriter->startElement('a:alpha');
858
            $objWriter->writeAttribute('val', $xAxis->getFillProperty('alpha'));
859
            $objWriter->endElement();
860
            $objWriter->endElement();
861
            $objWriter->endElement();
862
        }
863
864 12
        $objWriter->startElement('a:ln');
865
866 12
        $objWriter->writeAttribute('w', $xAxis->getLineStyleProperty('width'));
867 12
        $objWriter->writeAttribute('cap', $xAxis->getLineStyleProperty('cap'));
868 12
        $objWriter->writeAttribute('cmpd', $xAxis->getLineStyleProperty('compound'));
869
870 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...
871
            $objWriter->startElement('a:solidFill');
872
            $objWriter->startElement('a:' . $xAxis->getLineProperty('type'));
873
            $objWriter->writeAttribute('val', $xAxis->getLineProperty('value'));
874
            $objWriter->startElement('a:alpha');
875
            $objWriter->writeAttribute('val', $xAxis->getLineProperty('alpha'));
876
            $objWriter->endElement();
877
            $objWriter->endElement();
878
            $objWriter->endElement();
879
        }
880
881 12
        $objWriter->startElement('a:prstDash');
882 12
        $objWriter->writeAttribute('val', $xAxis->getLineStyleProperty('dash'));
883 12
        $objWriter->endElement();
884
885 12
        if ($xAxis->getLineStyleProperty('join') == 'miter') {
886
            $objWriter->startElement('a:miter');
887
            $objWriter->writeAttribute('lim', '800000');
888
            $objWriter->endElement();
889
        } else {
890 12
            $objWriter->startElement('a:bevel');
891 12
            $objWriter->endElement();
892
        }
893
894 12
        if (!is_null($xAxis->getLineStyleProperty(['arrow', 'head', 'type']))) {
895
            $objWriter->startElement('a:headEnd');
896
            $objWriter->writeAttribute('type', $xAxis->getLineStyleProperty(['arrow', 'head', 'type']));
897
            $objWriter->writeAttribute('w', $xAxis->getLineStyleArrowWidth('head'));
898
            $objWriter->writeAttribute('len', $xAxis->getLineStyleArrowLength('head'));
899
            $objWriter->endElement();
900
        }
901
902 12
        if (!is_null($xAxis->getLineStyleProperty(['arrow', 'end', 'type']))) {
903
            $objWriter->startElement('a:tailEnd');
904
            $objWriter->writeAttribute('type', $xAxis->getLineStyleProperty(['arrow', 'end', 'type']));
905
            $objWriter->writeAttribute('w', $xAxis->getLineStyleArrowWidth('end'));
906
            $objWriter->writeAttribute('len', $xAxis->getLineStyleArrowLength('end'));
907
            $objWriter->endElement();
908
        }
909
910 12
        $objWriter->endElement();
911
912 12
        $objWriter->startElement('a:effectLst');
913
914 12
        if (!is_null($xAxis->getGlowProperty('size'))) {
915
            $objWriter->startElement('a:glow');
916
            $objWriter->writeAttribute('rad', $xAxis->getGlowProperty('size'));
917
            $objWriter->startElement("a:{$xAxis->getGlowProperty(['color', 'type'])}");
918
            $objWriter->writeAttribute('val', $xAxis->getGlowProperty(['color', 'value']));
919
            $objWriter->startElement('a:alpha');
920
            $objWriter->writeAttribute('val', $xAxis->getGlowProperty(['color', 'alpha']));
921
            $objWriter->endElement();
922
            $objWriter->endElement();
923
            $objWriter->endElement();
924
        }
925
926 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...
927
            $objWriter->startElement("a:{$xAxis->getShadowProperty('effect')}");
928
929
            if (!is_null($xAxis->getShadowProperty('blur'))) {
930
                $objWriter->writeAttribute('blurRad', $xAxis->getShadowProperty('blur'));
931
            }
932
            if (!is_null($xAxis->getShadowProperty('distance'))) {
933
                $objWriter->writeAttribute('dist', $xAxis->getShadowProperty('distance'));
934
            }
935
            if (!is_null($xAxis->getShadowProperty('direction'))) {
936
                $objWriter->writeAttribute('dir', $xAxis->getShadowProperty('direction'));
937
            }
938
            if (!is_null($xAxis->getShadowProperty('algn'))) {
939
                $objWriter->writeAttribute('algn', $xAxis->getShadowProperty('algn'));
940
            }
941
            if (!is_null($xAxis->getShadowProperty(['size', 'sx']))) {
942
                $objWriter->writeAttribute('sx', $xAxis->getShadowProperty(['size', 'sx']));
943
            }
944
            if (!is_null($xAxis->getShadowProperty(['size', 'sy']))) {
945
                $objWriter->writeAttribute('sy', $xAxis->getShadowProperty(['size', 'sy']));
946
            }
947
            if (!is_null($xAxis->getShadowProperty(['size', 'kx']))) {
948
                $objWriter->writeAttribute('kx', $xAxis->getShadowProperty(['size', 'kx']));
949
            }
950
            if (!is_null($xAxis->getShadowProperty('rotWithShape'))) {
951
                $objWriter->writeAttribute('rotWithShape', $xAxis->getShadowProperty('rotWithShape'));
952
            }
953
954
            $objWriter->startElement("a:{$xAxis->getShadowProperty(['color', 'type'])}");
955
            $objWriter->writeAttribute('val', $xAxis->getShadowProperty(['color', 'value']));
956
            $objWriter->startElement('a:alpha');
957
            $objWriter->writeAttribute('val', $xAxis->getShadowProperty(['color', 'alpha']));
958
            $objWriter->endElement();
959
            $objWriter->endElement();
960
961
            $objWriter->endElement();
962
        }
963
964 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...
965
            $objWriter->startElement('a:softEdge');
966
            $objWriter->writeAttribute('rad', $xAxis->getSoftEdgesSize());
967
            $objWriter->endElement();
968
        }
969
970 12
        $objWriter->endElement(); //effectList
971 12
        $objWriter->endElement(); //end spPr
972
973 12
        if ($id1 > 0) {
974 12
            $objWriter->startElement('c:crossAx');
975 12
            $objWriter->writeAttribute('val', $id2);
976 12
            $objWriter->endElement();
977
978 12
            if (!is_null($xAxis->getAxisOptionsProperty('horizontal_crosses_value'))) {
979
                $objWriter->startElement('c:crossesAt');
980
                $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('horizontal_crosses_value'));
981
                $objWriter->endElement();
982
            } else {
983 12
                $objWriter->startElement('c:crosses');
984 12
                $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('horizontal_crosses'));
985 12
                $objWriter->endElement();
986
            }
987
988 12
            $objWriter->startElement('c:crossBetween');
989 12
            $objWriter->writeAttribute('val', 'midCat');
990 12
            $objWriter->endElement();
991
992 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...
993
                $objWriter->startElement('c:majorUnit');
994
                $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('major_unit'));
995
                $objWriter->endElement();
996
            }
997
998 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...
999
                $objWriter->startElement('c:minorUnit');
1000
                $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minor_unit'));
1001
                $objWriter->endElement();
1002
            }
1003
        }
1004
1005 12
        if ($isMultiLevelSeries) {
1006 1
            if ($groupType !== DataSeries::TYPE_BUBBLECHART) {
1007
                $objWriter->startElement('c:noMultiLvlLbl');
1008
                $objWriter->writeAttribute('val', 0);
1009
                $objWriter->endElement();
1010
            }
1011
        }
1012
1013 12
        $objWriter->endElement();
1014 12
    }
1015
1016
    /**
1017
     * Get the data series type(s) for a chart plot series.
1018
     *
1019
     * @param PlotArea $plotArea
1020
     *
1021
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
1022
     *
1023
     * @return string|array
1024
     */
1025 13
    private static function getChartType($plotArea)
1026
    {
1027 13
        $groupCount = $plotArea->getPlotGroupCount();
1028
1029 13
        if ($groupCount == 1) {
1030 12
            $chartType = [$plotArea->getPlotGroupByIndex(0)->getPlotType()];
1031
        } else {
1032 2
            $chartTypes = [];
1033 2
            for ($i = 0; $i < $groupCount; ++$i) {
1034 2
                $chartTypes[] = $plotArea->getPlotGroupByIndex($i)->getPlotType();
1035
            }
1036 2
            $chartType = array_unique($chartTypes);
1037 2
            if (count($chartTypes) == 0) {
1038
                throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Chart is not yet implemented');
1039
            }
1040
        }
1041
1042 13
        return $chartType;
1043
    }
1044
1045
    /**
1046
     * Write Plot Group (series of related plots).
1047
     *
1048
     * @param DataSeries $plotGroup
1049
     * @param string $groupType Type of plot for dataseries
1050
     * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
1051
     * @param bool &$catIsMultiLevelSeries Is category a multi-series category
1052
     * @param bool &$valIsMultiLevelSeries Is value set a multi-series set
1053
     * @param string &$plotGroupingType Type of grouping for multi-series values
1054
     * @param \PhpOffice\PhpSpreadsheet\Worksheet $pSheet
1055
     *
1056
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
1057
     */
1058 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...
1059
    {
1060 13
        if (is_null($plotGroup)) {
1061
            return;
1062
        }
1063
1064 13
        if (($groupType == DataSeries::TYPE_BARCHART) || ($groupType == DataSeries::TYPE_BARCHART_3D)) {
1065 7
            $objWriter->startElement('c:barDir');
1066 7
            $objWriter->writeAttribute('val', $plotGroup->getPlotDirection());
1067 7
            $objWriter->endElement();
1068
        }
1069
1070 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...
1071 9
            $plotGroupingType = $plotGroup->getPlotGrouping();
1072 9
            $objWriter->startElement('c:grouping');
1073 9
            $objWriter->writeAttribute('val', $plotGroupingType);
1074 9
            $objWriter->endElement();
1075
        }
1076
1077
        //    Get these details before the loop, because we can use the count to check for varyColors
1078 13
        $plotSeriesOrder = $plotGroup->getPlotOrder();
1079 13
        $plotSeriesCount = count($plotSeriesOrder);
1080
1081 13
        if (($groupType !== DataSeries::TYPE_RADARCHART) && ($groupType !== DataSeries::TYPE_STOCKCHART)) {
1082 11
            if ($groupType !== DataSeries::TYPE_LINECHART) {
1083 10
                if (($groupType == DataSeries::TYPE_PIECHART) || ($groupType == DataSeries::TYPE_PIECHART_3D) || ($groupType == DataSeries::TYPE_DONUTCHART) || ($plotSeriesCount > 1)) {
1084 9
                    $objWriter->startElement('c:varyColors');
1085 9
                    $objWriter->writeAttribute('val', 1);
1086 9
                    $objWriter->endElement();
1087
                } else {
1088 2
                    $objWriter->startElement('c:varyColors');
1089 2
                    $objWriter->writeAttribute('val', 0);
1090 2
                    $objWriter->endElement();
1091
                }
1092
            }
1093
        }
1094
1095 13
        foreach ($plotSeriesOrder as $plotSeriesIdx => $plotSeriesRef) {
1096 13
            $objWriter->startElement('c:ser');
1097
1098 13
            $objWriter->startElement('c:idx');
1099 13
            $objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesIdx);
1100 13
            $objWriter->endElement();
1101
1102 13
            $objWriter->startElement('c:order');
1103 13
            $objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesRef);
1104 13
            $objWriter->endElement();
1105
1106 13
            if (($groupType == DataSeries::TYPE_PIECHART) || ($groupType == DataSeries::TYPE_PIECHART_3D) || ($groupType == DataSeries::TYPE_DONUTCHART)) {
1107 2
                $objWriter->startElement('c:dPt');
1108 2
                $objWriter->startElement('c:idx');
1109 2
                $objWriter->writeAttribute('val', 3);
1110 2
                $objWriter->endElement();
1111
1112 2
                $objWriter->startElement('c:bubble3D');
1113 2
                $objWriter->writeAttribute('val', 0);
1114 2
                $objWriter->endElement();
1115
1116 2
                $objWriter->startElement('c:spPr');
1117 2
                $objWriter->startElement('a:solidFill');
1118 2
                $objWriter->startElement('a:srgbClr');
1119 2
                $objWriter->writeAttribute('val', 'FF9900');
1120 2
                $objWriter->endElement();
1121 2
                $objWriter->endElement();
1122 2
                $objWriter->endElement();
1123 2
                $objWriter->endElement();
1124
            }
1125
1126
            //    Labels
1127 13
            $plotSeriesLabel = $plotGroup->getPlotLabelByIndex($plotSeriesRef);
1128 13
            if ($plotSeriesLabel && ($plotSeriesLabel->getPointCount() > 0)) {
1129 13
                $objWriter->startElement('c:tx');
1130 13
                $objWriter->startElement('c:strRef');
1131 13
                $this->writePlotSeriesLabel($plotSeriesLabel, $objWriter);
1132 13
                $objWriter->endElement();
1133 13
                $objWriter->endElement();
1134
            }
1135
1136
            //    Formatting for the points
1137 13
            if (($groupType == DataSeries::TYPE_LINECHART) || ($groupType == DataSeries::TYPE_STOCKCHART)) {
1138 4
                $objWriter->startElement('c:spPr');
1139 4
                $objWriter->startElement('a:ln');
1140 4
                $objWriter->writeAttribute('w', 12700);
1141 4
                if ($groupType == DataSeries::TYPE_STOCKCHART) {
1142 2
                    $objWriter->startElement('a:noFill');
1143 2
                    $objWriter->endElement();
1144
                }
1145 4
                $objWriter->endElement();
1146 4
                $objWriter->endElement();
1147
            }
1148
1149 13
            $plotSeriesValues = $plotGroup->getPlotValuesByIndex($plotSeriesRef);
1150 13
            if ($plotSeriesValues) {
1151 13
                $plotSeriesMarker = $plotSeriesValues->getPointMarker();
1152 13
                if ($plotSeriesMarker) {
1153 1
                    $objWriter->startElement('c:marker');
1154 1
                    $objWriter->startElement('c:symbol');
1155 1
                    $objWriter->writeAttribute('val', $plotSeriesMarker);
1156 1
                    $objWriter->endElement();
1157
1158 1
                    if ($plotSeriesMarker !== 'none') {
1159 1
                        $objWriter->startElement('c:size');
1160 1
                        $objWriter->writeAttribute('val', 3);
1161 1
                        $objWriter->endElement();
1162
                    }
1163
1164 1
                    $objWriter->endElement();
1165
                }
1166
            }
1167
1168 13
            if (($groupType === DataSeries::TYPE_BARCHART) || ($groupType === DataSeries::TYPE_BARCHART_3D) || ($groupType === DataSeries::TYPE_BUBBLECHART)) {
1169 7
                $objWriter->startElement('c:invertIfNegative');
1170 7
                $objWriter->writeAttribute('val', 0);
1171 7
                $objWriter->endElement();
1172
            }
1173
1174
            //    Category Labels
1175 13
            $plotSeriesCategory = $plotGroup->getPlotCategoryByIndex($plotSeriesRef);
1176 13
            if ($plotSeriesCategory && ($plotSeriesCategory->getPointCount() > 0)) {
1177 13
                $catIsMultiLevelSeries = $catIsMultiLevelSeries || $plotSeriesCategory->isMultiLevelSeries();
1178
1179 13
                if (($groupType == DataSeries::TYPE_PIECHART) || ($groupType == DataSeries::TYPE_PIECHART_3D) || ($groupType == DataSeries::TYPE_DONUTCHART)) {
1180 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...
1181 1
                        $plotStyle = $plotGroup->getPlotStyle();
1182 1
                        if ($plotStyle) {
1183 1
                            $objWriter->startElement('c:explosion');
1184 1
                            $objWriter->writeAttribute('val', 25);
1185 1
                            $objWriter->endElement();
1186
                        }
1187
                    }
1188
                }
1189
1190 13
                if (($groupType === DataSeries::TYPE_BUBBLECHART) || ($groupType === DataSeries::TYPE_SCATTERCHART)) {
1191 2
                    $objWriter->startElement('c:xVal');
1192
                } else {
1193 12
                    $objWriter->startElement('c:cat');
1194
                }
1195
1196 13
                $this->writePlotSeriesValues($plotSeriesCategory, $objWriter, $groupType, 'str');
1197 13
                $objWriter->endElement();
1198
            }
1199
1200
            //    Values
1201 13
            if ($plotSeriesValues) {
1202 13
                $valIsMultiLevelSeries = $valIsMultiLevelSeries || $plotSeriesValues->isMultiLevelSeries();
1203
1204 13
                if (($groupType === DataSeries::TYPE_BUBBLECHART) || ($groupType === DataSeries::TYPE_SCATTERCHART)) {
1205 2
                    $objWriter->startElement('c:yVal');
1206
                } else {
1207 12
                    $objWriter->startElement('c:val');
1208
                }
1209
1210 13
                $this->writePlotSeriesValues($plotSeriesValues, $objWriter, $groupType, 'num');
1211 13
                $objWriter->endElement();
1212
            }
1213
1214 13
            if ($groupType === DataSeries::TYPE_BUBBLECHART) {
1215 1
                $this->writeBubbles($plotSeriesValues, $objWriter);
1216
            }
1217
1218 13
            $objWriter->endElement();
1219
        }
1220
1221 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 1095. 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...
1222 13
    }
1223
1224
    /**
1225
     * Write Plot Series Label.
1226
     *
1227
     * @param DataSeriesValues $plotSeriesLabel
1228
     * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
1229
     *
1230
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
1231
     */
1232 13
    private function writePlotSeriesLabel($plotSeriesLabel, $objWriter)
1233
    {
1234 13
        if (is_null($plotSeriesLabel)) {
1235
            return;
1236
        }
1237
1238 13
        $objWriter->startElement('c:f');
1239 13
        $objWriter->writeRawData($plotSeriesLabel->getDataSource());
1240 13
        $objWriter->endElement();
1241
1242 13
        $objWriter->startElement('c:strCache');
1243 13
        $objWriter->startElement('c:ptCount');
1244 13
        $objWriter->writeAttribute('val', $plotSeriesLabel->getPointCount());
1245 13
        $objWriter->endElement();
1246
1247 13
        foreach ($plotSeriesLabel->getDataValues() as $plotLabelKey => $plotLabelValue) {
1248 13
            $objWriter->startElement('c:pt');
1249 13
            $objWriter->writeAttribute('idx', $plotLabelKey);
1250
1251 13
            $objWriter->startElement('c:v');
1252 13
            $objWriter->writeRawData($plotLabelValue);
1253 13
            $objWriter->endElement();
1254 13
            $objWriter->endElement();
1255
        }
1256 13
        $objWriter->endElement();
1257 13
    }
1258
1259
    /**
1260
     * Write Plot Series Values.
1261
     *
1262
     * @param DataSeriesValues $plotSeriesValues
1263
     * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
1264
     * @param string $groupType Type of plot for dataseries
1265
     * @param string $dataType Datatype of series values
1266
     *
1267
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
1268
     */
1269 13
    private function writePlotSeriesValues($plotSeriesValues, \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $groupType, $dataType = 'str')
1270
    {
1271 13
        if (is_null($plotSeriesValues)) {
1272
            return;
1273
        }
1274
1275 13
        if ($plotSeriesValues->isMultiLevelSeries()) {
1276 2
            $levelCount = $plotSeriesValues->multiLevelCount();
1277
1278 2
            $objWriter->startElement('c:multiLvlStrRef');
1279
1280 2
            $objWriter->startElement('c:f');
1281 2
            $objWriter->writeRawData($plotSeriesValues->getDataSource());
1282 2
            $objWriter->endElement();
1283
1284 2
            $objWriter->startElement('c:multiLvlStrCache');
1285
1286 2
            $objWriter->startElement('c:ptCount');
1287 2
            $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount());
1288 2
            $objWriter->endElement();
1289
1290 2
            for ($level = 0; $level < $levelCount; ++$level) {
1291 2
                $objWriter->startElement('c:lvl');
1292
1293 2
                foreach ($plotSeriesValues->getDataValues() as $plotSeriesKey => $plotSeriesValue) {
1294 2
                    if (isset($plotSeriesValue[$level])) {
1295 2
                        $objWriter->startElement('c:pt');
1296 2
                        $objWriter->writeAttribute('idx', $plotSeriesKey);
1297
1298 2
                        $objWriter->startElement('c:v');
1299 2
                        $objWriter->writeRawData($plotSeriesValue[$level]);
1300 2
                        $objWriter->endElement();
1301 2
                        $objWriter->endElement();
1302
                    }
1303
                }
1304
1305 2
                $objWriter->endElement();
1306
            }
1307
1308 2
            $objWriter->endElement();
1309
1310 2
            $objWriter->endElement();
1311
        } else {
1312 13
            $objWriter->startElement('c:' . $dataType . 'Ref');
1313
1314 13
            $objWriter->startElement('c:f');
1315 13
            $objWriter->writeRawData($plotSeriesValues->getDataSource());
1316 13
            $objWriter->endElement();
1317
1318 13
            $objWriter->startElement('c:' . $dataType . 'Cache');
1319
1320 13
            if (($groupType != DataSeries::TYPE_PIECHART) && ($groupType != DataSeries::TYPE_PIECHART_3D) && ($groupType != DataSeries::TYPE_DONUTCHART)) {
1321 12
                if (($plotSeriesValues->getFormatCode() !== null) && ($plotSeriesValues->getFormatCode() !== '')) {
1322 1
                    $objWriter->startElement('c:formatCode');
1323 1
                    $objWriter->writeRawData($plotSeriesValues->getFormatCode());
1324 1
                    $objWriter->endElement();
1325
                }
1326
            }
1327
1328 13
            $objWriter->startElement('c:ptCount');
1329 13
            $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount());
1330 13
            $objWriter->endElement();
1331
1332 13
            $dataValues = $plotSeriesValues->getDataValues();
1333 13
            if (!empty($dataValues)) {
1334 13
                if (is_array($dataValues)) {
1335 13
                    foreach ($dataValues as $plotSeriesKey => $plotSeriesValue) {
1336 13
                        $objWriter->startElement('c:pt');
1337 13
                        $objWriter->writeAttribute('idx', $plotSeriesKey);
1338
1339 13
                        $objWriter->startElement('c:v');
1340 13
                        $objWriter->writeRawData($plotSeriesValue);
1341 13
                        $objWriter->endElement();
1342 13
                        $objWriter->endElement();
1343
                    }
1344
                }
1345
            }
1346
1347 13
            $objWriter->endElement();
1348
1349 13
            $objWriter->endElement();
1350
        }
1351 13
    }
1352
1353
    /**
1354
     * Write Bubble Chart Details.
1355
     *
1356
     * @param DataSeriesValues $plotSeriesValues
1357
     * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
1358
     *
1359
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
1360
     */
1361 1
    private function writeBubbles($plotSeriesValues, $objWriter)
1362
    {
1363 1
        if (is_null($plotSeriesValues)) {
1364
            return;
1365
        }
1366
1367 1
        $objWriter->startElement('c:bubbleSize');
1368 1
        $objWriter->startElement('c:numLit');
1369
1370 1
        $objWriter->startElement('c:formatCode');
1371 1
        $objWriter->writeRawData('General');
1372 1
        $objWriter->endElement();
1373
1374 1
        $objWriter->startElement('c:ptCount');
1375 1
        $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount());
1376 1
        $objWriter->endElement();
1377
1378 1
        $dataValues = $plotSeriesValues->getDataValues();
1379 1
        if (!empty($dataValues)) {
1380 1
            if (is_array($dataValues)) {
1381 1
                foreach ($dataValues as $plotSeriesKey => $plotSeriesValue) {
1382 1
                    $objWriter->startElement('c:pt');
1383 1
                    $objWriter->writeAttribute('idx', $plotSeriesKey);
1384 1
                    $objWriter->startElement('c:v');
1385 1
                    $objWriter->writeRawData(1);
1386 1
                    $objWriter->endElement();
1387 1
                    $objWriter->endElement();
1388
                }
1389
            }
1390
        }
1391
1392 1
        $objWriter->endElement();
1393 1
        $objWriter->endElement();
1394
1395 1
        $objWriter->startElement('c:bubble3D');
1396 1
        $objWriter->writeAttribute('val', 0);
1397 1
        $objWriter->endElement();
1398 1
    }
1399
1400
    /**
1401
     * Write Layout.
1402
     *
1403
     * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
1404
     * @param Layout $layout
1405
     *
1406
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
1407
     */
1408 13
    private function writeLayout(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, Layout $layout = null)
1409
    {
1410 13
        $objWriter->startElement('c:layout');
1411
1412 13
        if (!is_null($layout)) {
1413 3
            $objWriter->startElement('c:manualLayout');
1414
1415 3
            $layoutTarget = $layout->getLayoutTarget();
1416 3
            if (!is_null($layoutTarget)) {
1417 1
                $objWriter->startElement('c:layoutTarget');
1418 1
                $objWriter->writeAttribute('val', $layoutTarget);
1419 1
                $objWriter->endElement();
1420
            }
1421
1422 3
            $xMode = $layout->getXMode();
1423 3
            if (!is_null($xMode)) {
1424 1
                $objWriter->startElement('c:xMode');
1425 1
                $objWriter->writeAttribute('val', $xMode);
1426 1
                $objWriter->endElement();
1427
            }
1428
1429 3
            $yMode = $layout->getYMode();
1430 3
            if (!is_null($yMode)) {
1431 1
                $objWriter->startElement('c:yMode');
1432 1
                $objWriter->writeAttribute('val', $yMode);
1433 1
                $objWriter->endElement();
1434
            }
1435
1436 3
            $x = $layout->getXPosition();
1437 3
            if (!is_null($x)) {
1438 1
                $objWriter->startElement('c:x');
1439 1
                $objWriter->writeAttribute('val', $x);
1440 1
                $objWriter->endElement();
1441
            }
1442
1443 3
            $y = $layout->getYPosition();
1444 3
            if (!is_null($y)) {
1445 1
                $objWriter->startElement('c:y');
1446 1
                $objWriter->writeAttribute('val', $y);
1447 1
                $objWriter->endElement();
1448
            }
1449
1450 3
            $w = $layout->getWidth();
1451 3
            if (!is_null($w)) {
1452 1
                $objWriter->startElement('c:w');
1453 1
                $objWriter->writeAttribute('val', $w);
1454 1
                $objWriter->endElement();
1455
            }
1456
1457 3
            $h = $layout->getHeight();
1458 3
            if (!is_null($h)) {
1459 1
                $objWriter->startElement('c:h');
1460 1
                $objWriter->writeAttribute('val', $h);
1461 1
                $objWriter->endElement();
1462
            }
1463
1464 3
            $objWriter->endElement();
1465
        }
1466
1467 13
        $objWriter->endElement();
1468 13
    }
1469
1470
    /**
1471
     * Write Alternate Content block.
1472
     *
1473
     * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
1474
     *
1475
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
1476
     */
1477 13
    private function writeAlternateContent($objWriter)
1478
    {
1479 13
        $objWriter->startElement('mc:AlternateContent');
1480 13
        $objWriter->writeAttribute('xmlns:mc', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
1481
1482 13
        $objWriter->startElement('mc:Choice');
1483 13
        $objWriter->writeAttribute('xmlns:c14', 'http://schemas.microsoft.com/office/drawing/2007/8/2/chart');
1484 13
        $objWriter->writeAttribute('Requires', 'c14');
1485
1486 13
        $objWriter->startElement('c14:style');
1487 13
        $objWriter->writeAttribute('val', '102');
1488 13
        $objWriter->endElement();
1489 13
        $objWriter->endElement();
1490
1491 13
        $objWriter->startElement('mc:Fallback');
1492 13
        $objWriter->startElement('c:style');
1493 13
        $objWriter->writeAttribute('val', '2');
1494 13
        $objWriter->endElement();
1495 13
        $objWriter->endElement();
1496
1497 13
        $objWriter->endElement();
1498 13
    }
1499
1500
    /**
1501
     * Write Printer Settings.
1502
     *
1503
     * @param \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
1504
     *
1505
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
1506
     */
1507 13
    private function writePrintSettings($objWriter)
1508
    {
1509 13
        $objWriter->startElement('c:printSettings');
1510
1511 13
        $objWriter->startElement('c:headerFooter');
1512 13
        $objWriter->endElement();
1513
1514 13
        $objWriter->startElement('c:pageMargins');
1515 13
        $objWriter->writeAttribute('footer', 0.3);
1516 13
        $objWriter->writeAttribute('header', 0.3);
1517 13
        $objWriter->writeAttribute('r', 0.7);
1518 13
        $objWriter->writeAttribute('l', 0.7);
1519 13
        $objWriter->writeAttribute('t', 0.75);
1520 13
        $objWriter->writeAttribute('b', 0.75);
1521 13
        $objWriter->endElement();
1522
1523 13
        $objWriter->startElement('c:pageSetup');
1524 13
        $objWriter->writeAttribute('orientation', 'portrait');
1525 13
        $objWriter->endElement();
1526
1527 13
        $objWriter->endElement();
1528 13
    }
1529
}
1530