Completed
Push — develop ( 2b41bd...39b55d )
by Adrien
22:48
created

Chart::writePlotArea()   F

Complexity

Conditions 22
Paths 274

Size

Total Lines 122
Code Lines 85

Duplication

Lines 20
Ratio 16.39 %

Code Coverage

Tests 83
CRAP Score 22.0008

Importance

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

How to fix   Long Method    Complexity    Many Parameters   

Long Method

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

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

Commonly applied refactorings include:

Many Parameters

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

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;
4
5
use PhpOffice\PhpSpreadsheet\Chart\Axis;
6
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
7
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
8
use PhpOffice\PhpSpreadsheet\Chart\GridLines;
9
use PhpOffice\PhpSpreadsheet\Chart\Layout;
10
use PhpOffice\PhpSpreadsheet\Chart\Legend;
11
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
12
use PhpOffice\PhpSpreadsheet\Chart\Title;
13
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 13
    public function writeChart(\PhpOffice\PhpSpreadsheet\Chart $pChart = null, $calculateCellValues = true)
49
    {
50 13
        $this->calculateCellValues = $calculateCellValues;
51
52
        // Create XML writer
53 13
        $objWriter = null;
0 ignored issues
show
Unused Code introduced by
$objWriter is not used, you could remove the assignment.

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

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

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

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

Loading history...
54 13 View Code Duplication
        if ($this->getParentWriter()->getUseDiskCaching()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
Bug introduced by
It seems like you code against a concrete implementation and not the interface PhpOffice\PhpSpreadsheet\Writer\IWriter as the method getUseDiskCaching() does only exist in the following implementations of said interface: PhpOffice\PhpSpreadsheet\Writer\BaseWriter, PhpOffice\PhpSpreadsheet\Writer\CSV, PhpOffice\PhpSpreadsheet\Writer\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, PhpOffice\PhpSpreadsheet\Writer\Xlsx.

Let’s take a look at an example:

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

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

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

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

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

Available Fixes

  1. Change the type-hint for the parameter:

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

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

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
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\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, PhpOffice\PhpSpreadsheet\Writer\Xlsx.

Let’s take a look at an example:

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

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

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

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

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

Available Fixes

  1. Change the type-hint for the parameter:

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

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

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

Let’s take a look at an example:

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

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

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

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

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

Available Fixes

  1. Change the type-hint for the parameter:

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

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

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
150
151 13
        $objWriter->endElement();
152 13
        $objWriter->endElement();
153 13
        $objWriter->endElement();
154
155 13
        $this->writeLayout($objWriter, $title->getLayout());
156
157 13
        $objWriter->startElement('c:overlay');
158 13
        $objWriter->writeAttribute('val', 0);
159 13
        $objWriter->endElement();
160
161 13
        $objWriter->endElement();
162 13
    }
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 13
    private function writeLegend(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, Legend $legend = null)
173
    {
174 13
        if (is_null($legend)) {
175 2
            return;
176
        }
177
178 13
        $objWriter->startElement('c:legend');
179
180 13
        $objWriter->startElement('c:legendPos');
181 13
        $objWriter->writeAttribute('val', $legend->getPosition());
182 13
        $objWriter->endElement();
183
184 13
        $this->writeLayout($objWriter, $legend->getLayout());
185
186 13
        $objWriter->startElement('c:overlay');
187 13
        $objWriter->writeAttribute('val', ($legend->getOverlay()) ? '1' : '0');
188 13
        $objWriter->endElement();
189
190 13
        $objWriter->startElement('c:txPr');
191 13
        $objWriter->startElement('a:bodyPr');
192 13
        $objWriter->endElement();
193
194 13
        $objWriter->startElement('a:lstStyle');
195 13
        $objWriter->endElement();
196
197 13
        $objWriter->startElement('a:p');
198 13
        $objWriter->startElement('a:pPr');
199 13
        $objWriter->writeAttribute('rtl', 0);
200
201 13
        $objWriter->startElement('a:defRPr');
202 13
        $objWriter->endElement();
203 13
        $objWriter->endElement();
204
205 13
        $objWriter->startElement('a:endParaRPr');
206 13
        $objWriter->writeAttribute('lang', 'en-US');
207 13
        $objWriter->endElement();
208
209 13
        $objWriter->endElement();
210 13
        $objWriter->endElement();
211
212 13
        $objWriter->endElement();
213 13
    }
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 13
    private function writePlotArea(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet, PlotArea $plotArea, Title $xAxisLabel = null, Title $yAxisLabel = null, Axis $xAxis = null, Axis $yAxis = null, GridLines $majorGridlines = null, GridLines $minorGridlines = null)
229
    {
230 13
        if (is_null($plotArea)) {
231
            return;
232
        }
233
234 13
        $id1 = $id2 = 0;
235 13
        $this->_seriesIndex = 0;
0 ignored issues
show
Bug introduced by
The property _seriesIndex does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

There are different options of fixing this problem.

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

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

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

Loading history...
246 13
            $objWriter->startElement('c:' . $chartType);
247
248 13
            $groupCount = $plotArea->getPlotGroupCount();
249 13
            for ($i = 0; $i < $groupCount; ++$i) {
250 13
                $plotGroup = $plotArea->getPlotGroupByIndex($i);
251 13
                $groupType = $plotGroup->getPlotType();
252 13
                if ($groupType == $chartType) {
253 13
                    $plotStyle = $plotGroup->getPlotStyle();
254 13
                    if ($groupType === DataSeries::TYPE_RADARCHART) {
255 2
                        $objWriter->startElement('c:radarStyle');
256 2
                        $objWriter->writeAttribute('val', $plotStyle);
257 2
                        $objWriter->endElement();
258 12
                    } elseif ($groupType === DataSeries::TYPE_SCATTERCHART) {
259 2
                        $objWriter->startElement('c:scatterStyle');
260 2
                        $objWriter->writeAttribute('val', $plotStyle);
261 2
                        $objWriter->endElement();
262
                    }
263
264 13
                    $this->writePlotGroup($plotGroup, $chartType, $objWriter, $catIsMultiLevelSeries, $valIsMultiLevelSeries, $plotGroupingType, $pSheet);
265
                }
266
            }
267
268 13
            $this->writeDataLabels($objWriter, $layout);
269
270 13
            if ($chartType === DataSeries::TYPE_LINECHART) {
271
                //    Line only, Line3D can't be smoothed
272 3
                $objWriter->startElement('c:smooth');
273 3
                $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 3
                $objWriter->endElement();
275 12
            } elseif (($chartType === DataSeries::TYPE_BARCHART) || ($chartType === DataSeries::TYPE_BARCHART_3D)) {
276 7
                $objWriter->startElement('c:gapWidth');
277 7
                $objWriter->writeAttribute('val', 150);
278 7
                $objWriter->endElement();
279
280 7
                if ($plotGroupingType == 'percentStacked' || $plotGroupingType == 'stacked') {
281 2
                    $objWriter->startElement('c:overlap');
282 2
                    $objWriter->writeAttribute('val', 100);
283 7
                    $objWriter->endElement();
284
                }
285 8 View Code Duplication
            } elseif ($chartType === DataSeries::TYPE_BUBBLECHART) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
286 1
                $objWriter->startElement('c:bubbleScale');
287 1
                $objWriter->writeAttribute('val', 25);
288 1
                $objWriter->endElement();
289
290 1
                $objWriter->startElement('c:showNegBubbles');
291 1
                $objWriter->writeAttribute('val', 0);
292 1
                $objWriter->endElement();
293 8
            } elseif ($chartType === DataSeries::TYPE_STOCKCHART) {
294 2
                $objWriter->startElement('c:hiLowLines');
295 2
                $objWriter->endElement();
296
297 2
                $objWriter->startElement('c:upDownBars');
298
299 2
                $objWriter->startElement('c:gapWidth');
300 2
                $objWriter->writeAttribute('val', 300);
301 2
                $objWriter->endElement();
302
303 2
                $objWriter->startElement('c:upBars');
304 2
                $objWriter->endElement();
305
306 2
                $objWriter->startElement('c:downBars');
307 2
                $objWriter->endElement();
308
309 2
                $objWriter->endElement();
310
            }
311
312
            //    Generate 2 unique numbers to use for axId values
313 13
            $id1 = '75091328';
314 13
            $id2 = '75089408';
315
316 13
            if (($chartType !== DataSeries::TYPE_PIECHART) && ($chartType !== DataSeries::TYPE_PIECHART_3D) && ($chartType !== DataSeries::TYPE_DONUTCHART)) {
317 12
                $objWriter->startElement('c:axId');
318 12
                $objWriter->writeAttribute('val', $id1);
319 12
                $objWriter->endElement();
320 12
                $objWriter->startElement('c:axId');
321 12
                $objWriter->writeAttribute('val', $id2);
322 12
                $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 2
                $objWriter->startElement('c:firstSliceAng');
325 2
                $objWriter->writeAttribute('val', 0);
326 2
                $objWriter->endElement();
327
328 2
                if ($chartType === DataSeries::TYPE_DONUTCHART) {
329 2
                    $objWriter->startElement('c:holeSize');
330 2
                    $objWriter->writeAttribute('val', 50);
331 2
                    $objWriter->endElement();
332
                }
333
            }
334
335 13
            $objWriter->endElement();
336
        }
337
338 13
        if (($chartType !== DataSeries::TYPE_PIECHART) && ($chartType !== DataSeries::TYPE_PIECHART_3D) && ($chartType !== DataSeries::TYPE_DONUTCHART)) {
339 12
            if ($chartType === DataSeries::TYPE_BUBBLECHART) {
340 1
                $this->writeValueAxis($objWriter, $plotArea, $xAxisLabel, $chartType, $id1, $id2, $catIsMultiLevelSeries, $xAxis, $yAxis, $majorGridlines, $minorGridlines);
0 ignored issues
show
Bug introduced by
The variable $chartType seems to be defined by a foreach iteration on line 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 12
                $this->writeCategoryAxis($objWriter, $plotArea, $xAxisLabel, $chartType, $id1, $id2, $catIsMultiLevelSeries, $xAxis, $yAxis);
0 ignored issues
show
Bug introduced by
It seems like $xAxisLabel defined by parameter $xAxisLabel on line 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 12
            $this->writeValueAxis($objWriter, $plotArea, $yAxisLabel, $chartType, $id1, $id2, $valIsMultiLevelSeries, $xAxis, $yAxis, $majorGridlines, $minorGridlines);
0 ignored issues
show
Bug introduced by
It seems like $yAxisLabel defined by parameter $yAxisLabel on line 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 13
        $objWriter->endElement();
349 13
    }
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 13
    private function writeDataLabels($objWriter, Layout $chartLayout = null)
360
    {
361 13
        $objWriter->startElement('c:dLbls');
362
363 13
        $objWriter->startElement('c:showLegendKey');
364 13
        $showLegendKey = (empty($chartLayout)) ? 0 : $chartLayout->getShowLegendKey();
365 13
        $objWriter->writeAttribute('val', ((empty($showLegendKey)) ? 0 : 1));
366 13
        $objWriter->endElement();
367
368 13
        $objWriter->startElement('c:showVal');
369 13
        $showVal = (empty($chartLayout)) ? 0 : $chartLayout->getShowVal();
370 13
        $objWriter->writeAttribute('val', ((empty($showVal)) ? 0 : 1));
371 13
        $objWriter->endElement();
372
373 13
        $objWriter->startElement('c:showCatName');
374 13
        $showCatName = (empty($chartLayout)) ? 0 : $chartLayout->getShowCatName();
375 13
        $objWriter->writeAttribute('val', ((empty($showCatName)) ? 0 : 1));
376 13
        $objWriter->endElement();
377
378 13
        $objWriter->startElement('c:showSerName');
379 13
        $showSerName = (empty($chartLayout)) ? 0 : $chartLayout->getShowSerName();
380 13
        $objWriter->writeAttribute('val', ((empty($showSerName)) ? 0 : 1));
381 13
        $objWriter->endElement();
382
383 13
        $objWriter->startElement('c:showPercent');
384 13
        $showPercent = (empty($chartLayout)) ? 0 : $chartLayout->getShowPercent();
385 13
        $objWriter->writeAttribute('val', ((empty($showPercent)) ? 0 : 1));
386 13
        $objWriter->endElement();
387
388 13
        $objWriter->startElement('c:showBubbleSize');
389 13
        $showBubbleSize = (empty($chartLayout)) ? 0 : $chartLayout->getShowBubbleSize();
390 13
        $objWriter->writeAttribute('val', ((empty($showBubbleSize)) ? 0 : 1));
391 13
        $objWriter->endElement();
392
393 13
        $objWriter->startElement('c:showLeaderLines');
394 13
        $showLeaderLines = (empty($chartLayout)) ? 1 : $chartLayout->getShowLeaderLines();
395 13
        $objWriter->writeAttribute('val', ((empty($showLeaderLines)) ? 0 : 1));
396 13
        $objWriter->endElement();
397
398 13
        $objWriter->endElement();
399 13
    }
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 12
    private function writeCategoryAxis($objWriter, PlotArea $plotArea, $xAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries, $xAxis, $yAxis)
0 ignored issues
show
Unused Code introduced by
The parameter $plotArea is not used and could be removed.

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

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

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

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

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

Loading history...
415
    {
416 12
        $objWriter->startElement('c:catAx');
417
418 12
        if ($id1 > 0) {
419 12
            $objWriter->startElement('c:axId');
420 12
            $objWriter->writeAttribute('val', $id1);
421 12
            $objWriter->endElement();
422
        }
423
424 12
        $objWriter->startElement('c:scaling');
425 12
        $objWriter->startElement('c:orientation');
426 12
        $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('orientation'));
427 12
        $objWriter->endElement();
428 12
        $objWriter->endElement();
429
430 12
        $objWriter->startElement('c:delete');
431 12
        $objWriter->writeAttribute('val', 0);
432 12
        $objWriter->endElement();
433
434 12
        $objWriter->startElement('c:axPos');
435 12
        $objWriter->writeAttribute('val', 'b');
436 12
        $objWriter->endElement();
437
438 12 View Code Duplication
        if (!is_null($xAxisLabel)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
439 3
            $objWriter->startElement('c:title');
440 3
            $objWriter->startElement('c:tx');
441 3
            $objWriter->startElement('c:rich');
442
443 3
            $objWriter->startElement('a:bodyPr');
444 3
            $objWriter->endElement();
445
446 3
            $objWriter->startElement('a:lstStyle');
447 3
            $objWriter->endElement();
448
449 3
            $objWriter->startElement('a:p');
450 3
            $objWriter->startElement('a:r');
451
452 3
            $caption = $xAxisLabel->getCaption();
453 3
            if (is_array($caption)) {
454 1
                $caption = $caption[0];
455
            }
456 3
            $objWriter->startElement('a:t');
457 3
            $objWriter->writeRawData(\PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterPHP2OOXML($caption));
458 3
            $objWriter->endElement();
459
460 3
            $objWriter->endElement();
461 3
            $objWriter->endElement();
462 3
            $objWriter->endElement();
463 3
            $objWriter->endElement();
464
465 3
            $layout = $xAxisLabel->getLayout();
466 3
            $this->writeLayout($objWriter, $layout);
467
468 3
            $objWriter->startElement('c:overlay');
469 3
            $objWriter->writeAttribute('val', 0);
470 3
            $objWriter->endElement();
471
472 3
            $objWriter->endElement();
473
        }
474
475 12
        $objWriter->startElement('c:numFmt');
476 12
        $objWriter->writeAttribute('formatCode', $yAxis->getAxisNumberFormat());
477 12
        $objWriter->writeAttribute('sourceLinked', $yAxis->getAxisNumberSourceLinked());
478 12
        $objWriter->endElement();
479
480 12
        $objWriter->startElement('c:majorTickMark');
481 12
        $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('major_tick_mark'));
482 12
        $objWriter->endElement();
483
484 12
        $objWriter->startElement('c:minorTickMark');
485 12
        $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('minor_tick_mark'));
486 12
        $objWriter->endElement();
487
488 12
        $objWriter->startElement('c:tickLblPos');
489 12
        $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('axis_labels'));
490 12
        $objWriter->endElement();
491
492 12
        if ($id2 > 0) {
493 12
            $objWriter->startElement('c:crossAx');
494 12
            $objWriter->writeAttribute('val', $id2);
495 12
            $objWriter->endElement();
496
497 12
            $objWriter->startElement('c:crosses');
498 12
            $objWriter->writeAttribute('val', $yAxis->getAxisOptionsProperty('horizontal_crosses'));
499 12
            $objWriter->endElement();
500
        }
501
502 12
        $objWriter->startElement('c:auto');
503 12
        $objWriter->writeAttribute('val', 1);
504 12
        $objWriter->endElement();
505
506 12
        $objWriter->startElement('c:lblAlgn');
507 12
        $objWriter->writeAttribute('val', 'ctr');
508 12
        $objWriter->endElement();
509
510 12
        $objWriter->startElement('c:lblOffset');
511 12
        $objWriter->writeAttribute('val', 100);
512 12
        $objWriter->endElement();
513
514 12
        if ($isMultiLevelSeries) {
515 2
            $objWriter->startElement('c:noMultiLvlLbl');
516 2
            $objWriter->writeAttribute('val', 0);
517 2
            $objWriter->endElement();
518
        }
519 12
        $objWriter->endElement();
520 12
    }
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 12
    private function writeValueAxis($objWriter, PlotArea $plotArea, $yAxisLabel, $groupType, $id1, $id2, $isMultiLevelSeries, $xAxis, $yAxis, $majorGridlines, $minorGridlines)
0 ignored issues
show
Unused Code introduced by
The parameter $plotArea is not used and could be removed.

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

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

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

Loading history...
536
    {
537 12
        $objWriter->startElement('c:valAx');
538
539 12
        if ($id2 > 0) {
540 12
            $objWriter->startElement('c:axId');
541 12
            $objWriter->writeAttribute('val', $id2);
542 12
            $objWriter->endElement();
543
        }
544
545 12
        $objWriter->startElement('c:scaling');
546
547 12 View Code Duplication
        if (!is_null($xAxis->getAxisOptionsProperty('maximum'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
548
            $objWriter->startElement('c:max');
549
            $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('maximum'));
550
            $objWriter->endElement();
551
        }
552
553 12 View Code Duplication
        if (!is_null($xAxis->getAxisOptionsProperty('minimum'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
554
            $objWriter->startElement('c:min');
555
            $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minimum'));
556
            $objWriter->endElement();
557
        }
558
559 12
        $objWriter->startElement('c:orientation');
560 12
        $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('orientation'));
561
562 12
        $objWriter->endElement();
563 12
        $objWriter->endElement();
564
565 12
        $objWriter->startElement('c:delete');
566 12
        $objWriter->writeAttribute('val', 0);
567 12
        $objWriter->endElement();
568
569 12
        $objWriter->startElement('c:axPos');
570 12
        $objWriter->writeAttribute('val', 'l');
571 12
        $objWriter->endElement();
572
573 12
        $objWriter->startElement('c:majorGridlines');
574 12
        $objWriter->startElement('c:spPr');
575
576 12 View Code Duplication
        if (!is_null($majorGridlines->getLineColorProperty('value'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
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 12
        $objWriter->startElement('a:effectLst');
619
620 12 View Code Duplication
        if (!is_null($majorGridlines->getGlowSize())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
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 12 View Code Duplication
        if (!is_null($majorGridlines->getShadowProperty('presets'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
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 12 View Code Duplication
        if (!is_null($majorGridlines->getSoftEdgesSize())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
670
            $objWriter->startElement('a:softEdge');
671
            $objWriter->writeAttribute('rad', $majorGridlines->getSoftEdgesSize());
672
            $objWriter->endElement(); //end softEdge
673
        }
674
675 12
        $objWriter->endElement(); //end effectLst
676 12
        $objWriter->endElement(); //end spPr
677 12
        $objWriter->endElement(); //end majorGridLines
678
679 12
        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 12 View Code Duplication
        if (!is_null($yAxisLabel)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
787 10
            $objWriter->startElement('c:title');
788 10
            $objWriter->startElement('c:tx');
789 10
            $objWriter->startElement('c:rich');
790
791 10
            $objWriter->startElement('a:bodyPr');
792 10
            $objWriter->endElement();
793
794 10
            $objWriter->startElement('a:lstStyle');
795 10
            $objWriter->endElement();
796
797 10
            $objWriter->startElement('a:p');
798 10
            $objWriter->startElement('a:r');
799
800 10
            $caption = $yAxisLabel->getCaption();
801 10
            if (is_array($caption)) {
802 1
                $caption = $caption[0];
803
            }
804
805 10
            $objWriter->startElement('a:t');
806 10
            $objWriter->writeRawData(\PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterPHP2OOXML($caption));
807 10
            $objWriter->endElement();
808
809 10
            $objWriter->endElement();
810 10
            $objWriter->endElement();
811 10
            $objWriter->endElement();
812 10
            $objWriter->endElement();
813
814 10
            if ($groupType !== DataSeries::TYPE_BUBBLECHART) {
815 10
                $layout = $yAxisLabel->getLayout();
816 10
                $this->writeLayout($objWriter, $layout);
817
            }
818
819 10
            $objWriter->startElement('c:overlay');
820 10
            $objWriter->writeAttribute('val', 0);
821 10
            $objWriter->endElement();
822
823 10
            $objWriter->endElement();
824
        }
825
826 12
        $objWriter->startElement('c:numFmt');
827 12
        $objWriter->writeAttribute('formatCode', $xAxis->getAxisNumberFormat());
828 12
        $objWriter->writeAttribute('sourceLinked', $xAxis->getAxisNumberSourceLinked());
829 12
        $objWriter->endElement();
830
831 12
        $objWriter->startElement('c:majorTickMark');
832 12
        $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('major_tick_mark'));
833 12
        $objWriter->endElement();
834
835 12
        $objWriter->startElement('c:minorTickMark');
836 12
        $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minor_tick_mark'));
837 12
        $objWriter->endElement();
838
839 12
        $objWriter->startElement('c:tickLblPos');
840 12
        $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('axis_labels'));
841 12
        $objWriter->endElement();
842
843 12
        $objWriter->startElement('c:spPr');
844
845 12 View Code Duplication
        if (!is_null($xAxis->getFillProperty('value'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
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 12
        $objWriter->startElement('a:ln');
857
858 12
        $objWriter->writeAttribute('w', $xAxis->getLineStyleProperty('width'));
859 12
        $objWriter->writeAttribute('cap', $xAxis->getLineStyleProperty('cap'));
860 12
        $objWriter->writeAttribute('cmpd', $xAxis->getLineStyleProperty('compound'));
861
862 12 View Code Duplication
        if (!is_null($xAxis->getLineProperty('value'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
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 12
        $objWriter->startElement('a:prstDash');
874 12
        $objWriter->writeAttribute('val', $xAxis->getLineStyleProperty('dash'));
875 12
        $objWriter->endElement();
876
877 12
        if ($xAxis->getLineStyleProperty('join') == 'miter') {
878
            $objWriter->startElement('a:miter');
879
            $objWriter->writeAttribute('lim', '800000');
880
            $objWriter->endElement();
881
        } else {
882 12
            $objWriter->startElement('a:bevel');
883 12
            $objWriter->endElement();
884
        }
885
886 12
        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 12
        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 12
        $objWriter->endElement();
903
904 12
        $objWriter->startElement('a:effectLst');
905
906 12
        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 12 View Code Duplication
        if (!is_null($xAxis->getShadowProperty('presets'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
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 12 View Code Duplication
        if (!is_null($xAxis->getSoftEdgesSize())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
957
            $objWriter->startElement('a:softEdge');
958
            $objWriter->writeAttribute('rad', $xAxis->getSoftEdgesSize());
959
            $objWriter->endElement();
960
        }
961
962 12
        $objWriter->endElement(); //effectList
963 12
        $objWriter->endElement(); //end spPr
964
965 12
        if ($id1 > 0) {
966 12
            $objWriter->startElement('c:crossAx');
967 12
            $objWriter->writeAttribute('val', $id2);
968 12
            $objWriter->endElement();
969
970 12
            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 12
                $objWriter->startElement('c:crosses');
976 12
                $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('horizontal_crosses'));
977 12
                $objWriter->endElement();
978
            }
979
980 12
            $objWriter->startElement('c:crossBetween');
981 12
            $objWriter->writeAttribute('val', 'midCat');
982 12
            $objWriter->endElement();
983
984 12 View Code Duplication
            if (!is_null($xAxis->getAxisOptionsProperty('major_unit'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
985
                $objWriter->startElement('c:majorUnit');
986
                $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('major_unit'));
987
                $objWriter->endElement();
988
            }
989
990 12 View Code Duplication
            if (!is_null($xAxis->getAxisOptionsProperty('minor_unit'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
991
                $objWriter->startElement('c:minorUnit');
992
                $objWriter->writeAttribute('val', $xAxis->getAxisOptionsProperty('minor_unit'));
993
                $objWriter->endElement();
994
            }
995
        }
996
997 12
        if ($isMultiLevelSeries) {
998 1
            if ($groupType !== DataSeries::TYPE_BUBBLECHART) {
999
                $objWriter->startElement('c:noMultiLvlLbl');
1000
                $objWriter->writeAttribute('val', 0);
1001
                $objWriter->endElement();
1002
            }
1003
        }
1004
1005 12
        $objWriter->endElement();
1006 12
    }
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 13
    private static function getChartType($plotArea)
1017
    {
1018 13
        $groupCount = $plotArea->getPlotGroupCount();
1019
1020 13
        if ($groupCount == 1) {
1021 12
            $chartType = [$plotArea->getPlotGroupByIndex(0)->getPlotType()];
1022
        } else {
1023 2
            $chartTypes = [];
1024 2
            for ($i = 0; $i < $groupCount; ++$i) {
1025 2
                $chartTypes[] = $plotArea->getPlotGroupByIndex($i)->getPlotType();
1026
            }
1027 2
            $chartType = array_unique($chartTypes);
1028 2
            if (count($chartTypes) == 0) {
1029
                throw new \PhpOffice\PhpSpreadsheet\Writer\Exception('Chart is not yet implemented');
1030
            }
1031
        }
1032
1033 13
        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 13
    private function writePlotGroup($plotGroup, $groupType, $objWriter, &$catIsMultiLevelSeries, &$valIsMultiLevelSeries, &$plotGroupingType, \PhpOffice\PhpSpreadsheet\Worksheet $pSheet)
0 ignored issues
show
Unused Code introduced by
The parameter $pSheet is not used and could be removed.

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

Loading history...
1050
    {
1051 13
        if (is_null($plotGroup)) {
1052
            return;
1053
        }
1054
1055 13
        if (($groupType == DataSeries::TYPE_BARCHART) || ($groupType == DataSeries::TYPE_BARCHART_3D)) {
1056 7
            $objWriter->startElement('c:barDir');
1057 7
            $objWriter->writeAttribute('val', $plotGroup->getPlotDirection());
1058 7
            $objWriter->endElement();
1059
        }
1060
1061 13 View Code Duplication
        if (!is_null($plotGroup->getPlotGrouping())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
1062 9
            $plotGroupingType = $plotGroup->getPlotGrouping();
1063 9
            $objWriter->startElement('c:grouping');
1064 9
            $objWriter->writeAttribute('val', $plotGroupingType);
1065 9
            $objWriter->endElement();
1066
        }
1067
1068
        //    Get these details before the loop, because we can use the count to check for varyColors
1069 13
        $plotSeriesOrder = $plotGroup->getPlotOrder();
1070 13
        $plotSeriesCount = count($plotSeriesOrder);
1071
1072 13
        if (($groupType !== DataSeries::TYPE_RADARCHART) && ($groupType !== DataSeries::TYPE_STOCKCHART)) {
1073 11
            if ($groupType !== DataSeries::TYPE_LINECHART) {
1074 10
                if (($groupType == DataSeries::TYPE_PIECHART) || ($groupType == DataSeries::TYPE_PIECHART_3D) || ($groupType == DataSeries::TYPE_DONUTCHART) || ($plotSeriesCount > 1)) {
1075 9
                    $objWriter->startElement('c:varyColors');
1076 9
                    $objWriter->writeAttribute('val', 1);
1077 9
                    $objWriter->endElement();
1078
                } else {
1079 2
                    $objWriter->startElement('c:varyColors');
1080 2
                    $objWriter->writeAttribute('val', 0);
1081 2
                    $objWriter->endElement();
1082
                }
1083
            }
1084
        }
1085
1086 13
        foreach ($plotSeriesOrder as $plotSeriesIdx => $plotSeriesRef) {
1087 13
            $objWriter->startElement('c:ser');
1088
1089 13
            $objWriter->startElement('c:idx');
1090 13
            $objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesIdx);
1091 13
            $objWriter->endElement();
1092
1093 13
            $objWriter->startElement('c:order');
1094 13
            $objWriter->writeAttribute('val', $this->_seriesIndex + $plotSeriesRef);
1095 13
            $objWriter->endElement();
1096
1097 13
            if (($groupType == DataSeries::TYPE_PIECHART) || ($groupType == DataSeries::TYPE_PIECHART_3D) || ($groupType == DataSeries::TYPE_DONUTCHART)) {
1098 2
                $objWriter->startElement('c:dPt');
1099 2
                $objWriter->startElement('c:idx');
1100 2
                $objWriter->writeAttribute('val', 3);
1101 2
                $objWriter->endElement();
1102
1103 2
                $objWriter->startElement('c:bubble3D');
1104 2
                $objWriter->writeAttribute('val', 0);
1105 2
                $objWriter->endElement();
1106
1107 2
                $objWriter->startElement('c:spPr');
1108 2
                $objWriter->startElement('a:solidFill');
1109 2
                $objWriter->startElement('a:srgbClr');
1110 2
                $objWriter->writeAttribute('val', 'FF9900');
1111 2
                $objWriter->endElement();
1112 2
                $objWriter->endElement();
1113 2
                $objWriter->endElement();
1114 2
                $objWriter->endElement();
1115
            }
1116
1117
            //    Labels
1118 13
            $plotSeriesLabel = $plotGroup->getPlotLabelByIndex($plotSeriesRef);
1119 13
            if ($plotSeriesLabel && ($plotSeriesLabel->getPointCount() > 0)) {
1120 13
                $objWriter->startElement('c:tx');
1121 13
                $objWriter->startElement('c:strRef');
1122 13
                $this->writePlotSeriesLabel($plotSeriesLabel, $objWriter);
1123 13
                $objWriter->endElement();
1124 13
                $objWriter->endElement();
1125
            }
1126
1127
            //    Formatting for the points
1128 13
            if (($groupType == DataSeries::TYPE_LINECHART) || ($groupType == DataSeries::TYPE_STOCKCHART)) {
1129 4
                $objWriter->startElement('c:spPr');
1130 4
                $objWriter->startElement('a:ln');
1131 4
                $objWriter->writeAttribute('w', 12700);
1132 4
                if ($groupType == DataSeries::TYPE_STOCKCHART) {
1133 2
                    $objWriter->startElement('a:noFill');
1134 2
                    $objWriter->endElement();
1135
                }
1136 4
                $objWriter->endElement();
1137 4
                $objWriter->endElement();
1138
            }
1139
1140 13
            $plotSeriesValues = $plotGroup->getPlotValuesByIndex($plotSeriesRef);
1141 13
            if ($plotSeriesValues) {
1142 13
                $plotSeriesMarker = $plotSeriesValues->getPointMarker();
1143 13
                if ($plotSeriesMarker) {
1144 1
                    $objWriter->startElement('c:marker');
1145 1
                    $objWriter->startElement('c:symbol');
1146 1
                    $objWriter->writeAttribute('val', $plotSeriesMarker);
1147 1
                    $objWriter->endElement();
1148
1149 1
                    if ($plotSeriesMarker !== 'none') {
1150 1
                        $objWriter->startElement('c:size');
1151 1
                        $objWriter->writeAttribute('val', 3);
1152 1
                        $objWriter->endElement();
1153
                    }
1154
1155 1
                    $objWriter->endElement();
1156
                }
1157
            }
1158
1159 13
            if (($groupType === DataSeries::TYPE_BARCHART) || ($groupType === DataSeries::TYPE_BARCHART_3D) || ($groupType === DataSeries::TYPE_BUBBLECHART)) {
1160 7
                $objWriter->startElement('c:invertIfNegative');
1161 7
                $objWriter->writeAttribute('val', 0);
1162 7
                $objWriter->endElement();
1163
            }
1164
1165
            //    Category Labels
1166 13
            $plotSeriesCategory = $plotGroup->getPlotCategoryByIndex($plotSeriesRef);
1167 13
            if ($plotSeriesCategory && ($plotSeriesCategory->getPointCount() > 0)) {
1168 13
                $catIsMultiLevelSeries = $catIsMultiLevelSeries || $plotSeriesCategory->isMultiLevelSeries();
1169
1170 13
                if (($groupType == DataSeries::TYPE_PIECHART) || ($groupType == DataSeries::TYPE_PIECHART_3D) || ($groupType == DataSeries::TYPE_DONUTCHART)) {
1171 2 View Code Duplication
                    if (!is_null($plotGroup->getPlotStyle())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
1172 1
                        $plotStyle = $plotGroup->getPlotStyle();
1173 1
                        if ($plotStyle) {
1174 1
                            $objWriter->startElement('c:explosion');
1175 1
                            $objWriter->writeAttribute('val', 25);
1176 1
                            $objWriter->endElement();
1177
                        }
1178
                    }
1179
                }
1180
1181 13
                if (($groupType === DataSeries::TYPE_BUBBLECHART) || ($groupType === DataSeries::TYPE_SCATTERCHART)) {
1182 2
                    $objWriter->startElement('c:xVal');
1183
                } else {
1184 12
                    $objWriter->startElement('c:cat');
1185
                }
1186
1187 13
                $this->writePlotSeriesValues($plotSeriesCategory, $objWriter, $groupType, 'str');
1188 13
                $objWriter->endElement();
1189
            }
1190
1191
            //    Values
1192 13
            if ($plotSeriesValues) {
1193 13
                $valIsMultiLevelSeries = $valIsMultiLevelSeries || $plotSeriesValues->isMultiLevelSeries();
1194
1195 13
                if (($groupType === DataSeries::TYPE_BUBBLECHART) || ($groupType === DataSeries::TYPE_SCATTERCHART)) {
1196 2
                    $objWriter->startElement('c:yVal');
1197
                } else {
1198 12
                    $objWriter->startElement('c:val');
1199
                }
1200
1201 13
                $this->writePlotSeriesValues($plotSeriesValues, $objWriter, $groupType, 'num');
1202 13
                $objWriter->endElement();
1203
            }
1204
1205 13
            if ($groupType === DataSeries::TYPE_BUBBLECHART) {
1206 1
                $this->writeBubbles($plotSeriesValues, $objWriter);
1207
            }
1208
1209 13
            $objWriter->endElement();
1210
        }
1211
1212 13
        $this->_seriesIndex += $plotSeriesIdx + 1;
0 ignored issues
show
Bug introduced by
The variable $plotSeriesIdx seems to be defined by a foreach iteration on line 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 13
    }
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 13
    private function writePlotSeriesLabel($plotSeriesLabel, $objWriter)
1224
    {
1225 13
        if (is_null($plotSeriesLabel)) {
1226
            return;
1227
        }
1228
1229 13
        $objWriter->startElement('c:f');
1230 13
        $objWriter->writeRawData($plotSeriesLabel->getDataSource());
1231 13
        $objWriter->endElement();
1232
1233 13
        $objWriter->startElement('c:strCache');
1234 13
        $objWriter->startElement('c:ptCount');
1235 13
        $objWriter->writeAttribute('val', $plotSeriesLabel->getPointCount());
1236 13
        $objWriter->endElement();
1237
1238 13
        foreach ($plotSeriesLabel->getDataValues() as $plotLabelKey => $plotLabelValue) {
1239 13
            $objWriter->startElement('c:pt');
1240 13
            $objWriter->writeAttribute('idx', $plotLabelKey);
1241
1242 13
            $objWriter->startElement('c:v');
1243 13
            $objWriter->writeRawData($plotLabelValue);
1244 13
            $objWriter->endElement();
1245 13
            $objWriter->endElement();
1246
        }
1247 13
        $objWriter->endElement();
1248 13
    }
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 13
    private function writePlotSeriesValues($plotSeriesValues, \PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, $groupType, $dataType = 'str')
1261
    {
1262 13
        if (is_null($plotSeriesValues)) {
1263
            return;
1264
        }
1265
1266 13
        if ($plotSeriesValues->isMultiLevelSeries()) {
1267 2
            $levelCount = $plotSeriesValues->multiLevelCount();
1268
1269 2
            $objWriter->startElement('c:multiLvlStrRef');
1270
1271 2
            $objWriter->startElement('c:f');
1272 2
            $objWriter->writeRawData($plotSeriesValues->getDataSource());
1273 2
            $objWriter->endElement();
1274
1275 2
            $objWriter->startElement('c:multiLvlStrCache');
1276
1277 2
            $objWriter->startElement('c:ptCount');
1278 2
            $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount());
1279 2
            $objWriter->endElement();
1280
1281 2
            for ($level = 0; $level < $levelCount; ++$level) {
1282 2
                $objWriter->startElement('c:lvl');
1283
1284 2
                foreach ($plotSeriesValues->getDataValues() as $plotSeriesKey => $plotSeriesValue) {
1285 2
                    if (isset($plotSeriesValue[$level])) {
1286 2
                        $objWriter->startElement('c:pt');
1287 2
                        $objWriter->writeAttribute('idx', $plotSeriesKey);
1288
1289 2
                        $objWriter->startElement('c:v');
1290 2
                        $objWriter->writeRawData($plotSeriesValue[$level]);
1291 2
                        $objWriter->endElement();
1292 2
                        $objWriter->endElement();
1293
                    }
1294
                }
1295
1296 2
                $objWriter->endElement();
1297
            }
1298
1299 2
            $objWriter->endElement();
1300
1301 2
            $objWriter->endElement();
1302
        } else {
1303 13
            $objWriter->startElement('c:' . $dataType . 'Ref');
1304
1305 13
            $objWriter->startElement('c:f');
1306 13
            $objWriter->writeRawData($plotSeriesValues->getDataSource());
1307 13
            $objWriter->endElement();
1308
1309 13
            $objWriter->startElement('c:' . $dataType . 'Cache');
1310
1311 13
            if (($groupType != DataSeries::TYPE_PIECHART) && ($groupType != DataSeries::TYPE_PIECHART_3D) && ($groupType != DataSeries::TYPE_DONUTCHART)) {
1312 12
                if (($plotSeriesValues->getFormatCode() !== null) && ($plotSeriesValues->getFormatCode() !== '')) {
1313 1
                    $objWriter->startElement('c:formatCode');
1314 1
                    $objWriter->writeRawData($plotSeriesValues->getFormatCode());
1315 1
                    $objWriter->endElement();
1316
                }
1317
            }
1318
1319 13
            $objWriter->startElement('c:ptCount');
1320 13
            $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount());
1321 13
            $objWriter->endElement();
1322
1323 13
            $dataValues = $plotSeriesValues->getDataValues();
1324 13
            if (!empty($dataValues)) {
1325 13
                if (is_array($dataValues)) {
1326 13
                    foreach ($dataValues as $plotSeriesKey => $plotSeriesValue) {
1327 13
                        $objWriter->startElement('c:pt');
1328 13
                        $objWriter->writeAttribute('idx', $plotSeriesKey);
1329
1330 13
                        $objWriter->startElement('c:v');
1331 13
                        $objWriter->writeRawData($plotSeriesValue);
1332 13
                        $objWriter->endElement();
1333 13
                        $objWriter->endElement();
1334
                    }
1335
                }
1336
            }
1337
1338 13
            $objWriter->endElement();
1339
1340 13
            $objWriter->endElement();
1341
        }
1342 13
    }
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 1
    private function writeBubbles($plotSeriesValues, $objWriter)
1353
    {
1354 1
        if (is_null($plotSeriesValues)) {
1355
            return;
1356
        }
1357
1358 1
        $objWriter->startElement('c:bubbleSize');
1359 1
        $objWriter->startElement('c:numLit');
1360
1361 1
        $objWriter->startElement('c:formatCode');
1362 1
        $objWriter->writeRawData('General');
1363 1
        $objWriter->endElement();
1364
1365 1
        $objWriter->startElement('c:ptCount');
1366 1
        $objWriter->writeAttribute('val', $plotSeriesValues->getPointCount());
1367 1
        $objWriter->endElement();
1368
1369 1
        $dataValues = $plotSeriesValues->getDataValues();
1370 1
        if (!empty($dataValues)) {
1371 1
            if (is_array($dataValues)) {
1372 1
                foreach ($dataValues as $plotSeriesKey => $plotSeriesValue) {
1373 1
                    $objWriter->startElement('c:pt');
1374 1
                    $objWriter->writeAttribute('idx', $plotSeriesKey);
1375 1
                    $objWriter->startElement('c:v');
1376 1
                    $objWriter->writeRawData(1);
1377 1
                    $objWriter->endElement();
1378 1
                    $objWriter->endElement();
1379
                }
1380
            }
1381
        }
1382
1383 1
        $objWriter->endElement();
1384 1
        $objWriter->endElement();
1385
1386 1
        $objWriter->startElement('c:bubble3D');
1387 1
        $objWriter->writeAttribute('val', 0);
1388 1
        $objWriter->endElement();
1389 1
    }
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 13
    private function writeLayout(\PhpOffice\PhpSpreadsheet\Shared\XMLWriter $objWriter, Layout $layout = null)
1400
    {
1401 13
        $objWriter->startElement('c:layout');
1402
1403 13
        if (!is_null($layout)) {
1404 3
            $objWriter->startElement('c:manualLayout');
1405
1406 3
            $layoutTarget = $layout->getLayoutTarget();
1407 3
            if (!is_null($layoutTarget)) {
1408 1
                $objWriter->startElement('c:layoutTarget');
1409 1
                $objWriter->writeAttribute('val', $layoutTarget);
1410 1
                $objWriter->endElement();
1411
            }
1412
1413 3
            $xMode = $layout->getXMode();
1414 3
            if (!is_null($xMode)) {
1415 1
                $objWriter->startElement('c:xMode');
1416 1
                $objWriter->writeAttribute('val', $xMode);
1417 1
                $objWriter->endElement();
1418
            }
1419
1420 3
            $yMode = $layout->getYMode();
1421 3
            if (!is_null($yMode)) {
1422 1
                $objWriter->startElement('c:yMode');
1423 1
                $objWriter->writeAttribute('val', $yMode);
1424 1
                $objWriter->endElement();
1425
            }
1426
1427 3
            $x = $layout->getXPosition();
1428 3
            if (!is_null($x)) {
1429 1
                $objWriter->startElement('c:x');
1430 1
                $objWriter->writeAttribute('val', $x);
1431 1
                $objWriter->endElement();
1432
            }
1433
1434 3
            $y = $layout->getYPosition();
1435 3
            if (!is_null($y)) {
1436 1
                $objWriter->startElement('c:y');
1437 1
                $objWriter->writeAttribute('val', $y);
1438 1
                $objWriter->endElement();
1439
            }
1440
1441 3
            $w = $layout->getWidth();
1442 3
            if (!is_null($w)) {
1443 1
                $objWriter->startElement('c:w');
1444 1
                $objWriter->writeAttribute('val', $w);
1445 1
                $objWriter->endElement();
1446
            }
1447
1448 3
            $h = $layout->getHeight();
1449 3
            if (!is_null($h)) {
1450 1
                $objWriter->startElement('c:h');
1451 1
                $objWriter->writeAttribute('val', $h);
1452 1
                $objWriter->endElement();
1453
            }
1454
1455 3
            $objWriter->endElement();
1456
        }
1457
1458 13
        $objWriter->endElement();
1459 13
    }
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 13
    private function writeAlternateContent($objWriter)
1469
    {
1470 13
        $objWriter->startElement('mc:AlternateContent');
1471 13
        $objWriter->writeAttribute('xmlns:mc', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
1472
1473 13
        $objWriter->startElement('mc:Choice');
1474 13
        $objWriter->writeAttribute('xmlns:c14', 'http://schemas.microsoft.com/office/drawing/2007/8/2/chart');
1475 13
        $objWriter->writeAttribute('Requires', 'c14');
1476
1477 13
        $objWriter->startElement('c14:style');
1478 13
        $objWriter->writeAttribute('val', '102');
1479 13
        $objWriter->endElement();
1480 13
        $objWriter->endElement();
1481
1482 13
        $objWriter->startElement('mc:Fallback');
1483 13
        $objWriter->startElement('c:style');
1484 13
        $objWriter->writeAttribute('val', '2');
1485 13
        $objWriter->endElement();
1486 13
        $objWriter->endElement();
1487
1488 13
        $objWriter->endElement();
1489 13
    }
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 13
    private function writePrintSettings($objWriter)
1499
    {
1500 13
        $objWriter->startElement('c:printSettings');
1501
1502 13
        $objWriter->startElement('c:headerFooter');
1503 13
        $objWriter->endElement();
1504
1505 13
        $objWriter->startElement('c:pageMargins');
1506 13
        $objWriter->writeAttribute('footer', 0.3);
1507 13
        $objWriter->writeAttribute('header', 0.3);
1508 13
        $objWriter->writeAttribute('r', 0.7);
1509 13
        $objWriter->writeAttribute('l', 0.7);
1510 13
        $objWriter->writeAttribute('t', 0.75);
1511 13
        $objWriter->writeAttribute('b', 0.75);
1512 13
        $objWriter->endElement();
1513
1514 13
        $objWriter->startElement('c:pageSetup');
1515 13
        $objWriter->writeAttribute('orientation', 'portrait');
1516 13
        $objWriter->endElement();
1517
1518 13
        $objWriter->endElement();
1519 13
    }
1520
}
1521