Completed
Push — develop ( 2922a1...cfa1fe )
by Adrien
24:40
created

Chart::writeValueAxis()   F

Complexity

Conditions 60
Paths 0

Size

Total Lines 472
Code Lines 341

Duplication

Lines 307
Ratio 65.04 %

Code Coverage

Tests 0
CRAP Score 3660

Importance

Changes 0
Metric Value
cc 60
eloc 341
nc 0
nop 11
dl 307
loc 472
rs 2
c 0
b 0
f 0
ccs 0
cts 402
cp 0
crap 3660

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

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

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Writer\Excel2007;
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
 * @copyright  Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
33
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
34
 * @version    ##VERSION##, ##DATE##
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
     *
45
     * @throws  \PhpOffice\PhpSpreadsheet\Writer\Exception
46
     * @return  string            XML Output
47
     */
48
    public function writeChart(\PhpOffice\PhpSpreadsheet\Chart $pChart = null, $calculateCellValues = true)
49
    {
50
        $this->calculateCellValues = $calculateCellValues;
51
52
        // Create XML writer
53
        $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...
54 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\Excel2007, PhpOffice\PhpSpreadsheet\Writer\Excel5, PhpOffice\PhpSpreadsheet\Writer\HTML, PhpOffice\PhpSpreadsheet\Writer\OpenDocument, PhpOffice\PhpSpreadsheet\Writer\PDF\Core, PhpOffice\PhpSpreadsheet\Writer\PDF\DomPDF, PhpOffice\PhpSpreadsheet\Writer\PDF\MPDF, PhpOffice\PhpSpreadsheet\Writer\PDF\TcPDF.

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...
55
            $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\Excel2007, PhpOffice\PhpSpreadsheet\Writer\Excel5, PhpOffice\PhpSpreadsheet\Writer\HTML, PhpOffice\PhpSpreadsheet\Writer\OpenDocument, PhpOffice\PhpSpreadsheet\Writer\PDF\Core, PhpOffice\PhpSpreadsheet\Writer\PDF\DomPDF, PhpOffice\PhpSpreadsheet\Writer\PDF\MPDF, PhpOffice\PhpSpreadsheet\Writer\PDF\TcPDF.

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...
56
        } else {
57
            $objWriter = new \PhpOffice\PhpSpreadsheet\Shared\XMLWriter(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter::STORAGE_MEMORY);
58
        }
59
        //    Ensure that data series values are up-to-date before we save
60
        if ($this->calculateCellValues) {
61
            $pChart->refresh();
0 ignored issues
show
Bug introduced by
It seems like $pChart is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
62
        }
63
64
        // XML header
65
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');
66
67
        // c:chartSpace
68
        $objWriter->startElement('c:chartSpace');
69
        $objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
70
        $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
71
        $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
72
73
        $objWriter->startElement('c:date1904');
74
        $objWriter->writeAttribute('val', 0);
75
        $objWriter->endElement();
76
        $objWriter->startElement('c:lang');
77
        $objWriter->writeAttribute('val', 'en-GB');
78
        $objWriter->endElement();
79
        $objWriter->startElement('c:roundedCorners');
80
        $objWriter->writeAttribute('val', 0);
81
        $objWriter->endElement();
82
83
        $this->writeAlternateContent($objWriter);
84
85
        $objWriter->startElement('c:chart');
86
87
        $this->writeTitle($objWriter, $pChart->getTitle());
88
89
        $objWriter->startElement('c:autoTitleDeleted');
90
        $objWriter->writeAttribute('val', 0);
91
        $objWriter->endElement();
92
93
        $this->writePlotArea($objWriter, $pChart->getWorksheet(), $pChart->getPlotArea(), $pChart->getXAxisLabel(), $pChart->getYAxisLabel(), $pChart->getChartAxisX(), $pChart->getChartAxisY(), $pChart->getMajorGridlines(), $pChart->getMinorGridlines());
94
95
        $this->writeLegend($objWriter, $pChart->getLegend());
96
97
        $objWriter->startElement('c:plotVisOnly');
98
        $objWriter->writeAttribute('val', 1);
99
        $objWriter->endElement();
100
101
        $objWriter->startElement('c:dispBlanksAs');
102
        $objWriter->writeAttribute('val', 'gap');
103
        $objWriter->endElement();
104
105
        $objWriter->startElement('c:showDLblsOverMax');
106
        $objWriter->writeAttribute('val', 0);
107
        $objWriter->endElement();
108
109
        $objWriter->endElement();
110
111
        $this->writePrintSettings($objWriter);
112
113
        $objWriter->endElement();
114
115
        // Return
116
        return $objWriter->getData();
117
    }
118
119
    /**
120
     * Write Chart Title
121
     *
122
     * @param  \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
123
     * @param  Title $title
124
     *
125
     * @throws  \PhpOffice\PhpSpreadsheet\Writer\Exception
126
     */
127
    private function writeTitle(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, Title $title = null)
128
    {
129
        if (is_null($title)) {
130
            return;
131
        }
132
133
        $objWriter->startElement('c:title');
134
        $objWriter->startElement('c:tx');
135
        $objWriter->startElement('c:rich');
136
137
        $objWriter->startElement('a:bodyPr');
138
        $objWriter->endElement();
139
140
        $objWriter->startElement('a:lstStyle');
141
        $objWriter->endElement();
142
143
        $objWriter->startElement('a:p');
144
145
        $caption = $title->getCaption();
146
        if ((is_array($caption)) && (count($caption) > 0)) {
147
            $caption = $caption[0];
148
        }
149
        $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\Excel2007, PhpOffice\PhpSpreadsheet\Writer\OpenDocument.

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...
150
151
        $objWriter->endElement();
152
        $objWriter->endElement();
153
        $objWriter->endElement();
154
155
        $this->writeLayout($objWriter, $title->getLayout());
156
157
        $objWriter->startElement('c:overlay');
158
        $objWriter->writeAttribute('val', 0);
159
        $objWriter->endElement();
160
161
        $objWriter->endElement();
162
    }
163
164
    /**
165
     * Write Chart Legend
166
     *
167
     * @param  \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
168
     * @param  Legend $legend
169
     *
170
     * @throws  \PhpOffice\PhpSpreadsheet\Writer\Exception
171
     */
172
    private function writeLegend(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, Legend $legend = null)
173
    {
174
        if (is_null($legend)) {
175
            return;
176
        }
177
178
        $objWriter->startElement('c:legend');
179
180
        $objWriter->startElement('c:legendPos');
181
        $objWriter->writeAttribute('val', $legend->getPosition());
182
        $objWriter->endElement();
183
184
        $this->writeLayout($objWriter, $legend->getLayout());
185
186
        $objWriter->startElement('c:overlay');
187
        $objWriter->writeAttribute('val', ($legend->getOverlay()) ? '1' : '0');
188
        $objWriter->endElement();
189
190
        $objWriter->startElement('c:txPr');
191
        $objWriter->startElement('a:bodyPr');
192
        $objWriter->endElement();
193
194
        $objWriter->startElement('a:lstStyle');
195
        $objWriter->endElement();
196
197
        $objWriter->startElement('a:p');
198
        $objWriter->startElement('a:pPr');
199
        $objWriter->writeAttribute('rtl', 0);
200
201
        $objWriter->startElement('a:defRPr');
202
        $objWriter->endElement();
203
        $objWriter->endElement();
204
205
        $objWriter->startElement('a:endParaRPr');
206
        $objWriter->writeAttribute('lang', 'en-US');
207
        $objWriter->endElement();
208
209
        $objWriter->endElement();
210
        $objWriter->endElement();
211
212
        $objWriter->endElement();
213
    }
214
215
    /**
216
     * Write Chart Plot Area
217
     *
218
     * @param  \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter XML Writer
219
     * @param  \PhpOffice\PhpSpreadsheet\Worksheet $pSheet
220
     * @param  PlotArea $plotArea
221
     * @param  Title $xAxisLabel
222
     * @param  Title $yAxisLabel
223
     * @param  Axis $xAxis
224
     * @param  Axis $yAxis
225
     *
226
     * @throws  \PhpOffice\PhpSpreadsheet\Writer\Exception
227
     */
228
    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)
229
    {
230
        if (is_null($plotArea)) {
231
            return;
232
        }
233
234
        $id1 = $id2 = 0;
235
        $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...
236
        $objWriter->startElement('c:plotArea');
237
238
        $layout = $plotArea->getLayout();
239
240
        $this->writeLayout($objWriter, $layout);
241
242
        $chartTypes = self::getChartType($plotArea);
243
        $catIsMultiLevelSeries = $valIsMultiLevelSeries = false;
244
        $plotGroupingType = '';
245
        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...
246
            $objWriter->startElement('c:' . $chartType);
247
248
            $groupCount = $plotArea->getPlotGroupCount();
249
            for ($i = 0; $i < $groupCount; ++$i) {
250
                $plotGroup = $plotArea->getPlotGroupByIndex($i);
251
                $groupType = $plotGroup->getPlotType();
252
                if ($groupType == $chartType) {
253
                    $plotStyle = $plotGroup->getPlotStyle();
254
                    if ($groupType === DataSeries::TYPE_RADARCHART) {
255
                        $objWriter->startElement('c:radarStyle');
256
                        $objWriter->writeAttribute('val', $plotStyle);
257
                        $objWriter->endElement();
258
                    } elseif ($groupType === DataSeries::TYPE_SCATTERCHART) {
259
                        $objWriter->startElement('c:scatterStyle');
260
                        $objWriter->writeAttribute('val', $plotStyle);
261
                        $objWriter->endElement();
262
                    }
263
264
                    $this->writePlotGroup($plotGroup, $chartType, $objWriter, $catIsMultiLevelSeries, $valIsMultiLevelSeries, $plotGroupingType, $pSheet);
265
                }
266
            }
267
268
            $this->writeDataLabels($objWriter, $layout);
269
270
            if ($chartType === DataSeries::TYPE_LINECHART) {
271
                //    Line only, Line3D can't be smoothed
272
                $objWriter->startElement('c:smooth');
273
                $objWriter->writeAttribute('val', (integer) $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...
274
                $objWriter->endElement();
275
            } elseif (($chartType === DataSeries::TYPE_BARCHART) || ($chartType === DataSeries::TYPE_BARCHART_3D)) {
276
                $objWriter->startElement('c:gapWidth');
277
                $objWriter->writeAttribute('val', 150);
278
                $objWriter->endElement();
279
280
                if ($plotGroupingType == 'percentStacked' || $plotGroupingType == 'stacked') {
281
                    $objWriter->startElement('c:overlap');
282
                    $objWriter->writeAttribute('val', 100);
283
                    $objWriter->endElement();
284
                }
285 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...
286
                $objWriter->startElement('c:bubbleScale');
287
                $objWriter->writeAttribute('val', 25);
288
                $objWriter->endElement();
289
290
                $objWriter->startElement('c:showNegBubbles');
291
                $objWriter->writeAttribute('val', 0);
292
                $objWriter->endElement();
293
            } elseif ($chartType === DataSeries::TYPE_STOCKCHART) {
294
                $objWriter->startElement('c:hiLowLines');
295
                $objWriter->endElement();
296
297
                $objWriter->startElement('c:upDownBars');
298
299
                $objWriter->startElement('c:gapWidth');
300
                $objWriter->writeAttribute('val', 300);
301
                $objWriter->endElement();
302
303
                $objWriter->startElement('c:upBars');
304
                $objWriter->endElement();
305
306
                $objWriter->startElement('c:downBars');
307
                $objWriter->endElement();
308
309
                $objWriter->endElement();
310
            }
311
312
            //    Generate 2 unique numbers to use for axId values
313
            $id1 = '75091328';
314
            $id2 = '75089408';
315
316
            if (($chartType !== DataSeries::TYPE_PIECHART) && ($chartType !== DataSeries::TYPE_PIECHART_3D) && ($chartType !== DataSeries::TYPE_DONUTCHART)) {
317
                $objWriter->startElement('c:axId');
318
                $objWriter->writeAttribute('val', $id1);
319
                $objWriter->endElement();
320
                $objWriter->startElement('c:axId');
321
                $objWriter->writeAttribute('val', $id2);
322
                $objWriter->endElement();
323 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...
324
                $objWriter->startElement('c:firstSliceAng');
325
                $objWriter->writeAttribute('val', 0);
326
                $objWriter->endElement();
327
328
                if ($chartType === DataSeries::TYPE_DONUTCHART) {
329
                    $objWriter->startElement('c:holeSize');
330
                    $objWriter->writeAttribute('val', 50);
331
                    $objWriter->endElement();
332
                }
333
            }
334
335
            $objWriter->endElement();
336
        }
337
338
        if (($chartType !== DataSeries::TYPE_PIECHART) && ($chartType !== DataSeries::TYPE_PIECHART_3D) && ($chartType !== DataSeries::TYPE_DONUTCHART)) {
339
            if ($chartType === DataSeries::TYPE_BUBBLECHART) {
340
                $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 245. 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 228 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...
341
            } else {
342
                $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 228 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...
343
            }
344
345
            $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 228 can be null; however, PhpOffice\PhpSpreadsheet...Chart::writeValueAxis() does not accept null, maybe add an additional type check?

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

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

function notNullable(stdClass $x) { }

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

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

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