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

Drawing::writeDrawing()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 118
Code Lines 66

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 65
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 66
nc 3
nop 3
dl 0
loc 118
ccs 65
cts 66
cp 0.9848
crap 3
rs 8.2857
c 0
b 0
f 0

How to fix   Long Method   

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:

1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;
4
5
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
6
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
7
use PhpOffice\PhpSpreadsheet\Spreadsheet;
8
use PhpOffice\PhpSpreadsheet\Worksheet\BaseDrawing;
9
use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing;
10
use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException;
11
12
class Drawing extends WriterPart
13
{
14
    /**
15
     * Write drawings to XML format.
16
     *
17
     * @param \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet
18
     * @param bool $includeCharts Flag indicating if we should include drawing details for charts
19
     *
20
     * @throws WriterException
21
     *
22
     * @return string XML Output
23
     */
24 22
    public function writeDrawings(\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet, $includeCharts = false)
25
    {
26
        // Create XML writer
27 22
        $objWriter = null;
28 22 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...
29
            $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
30
        } else {
31 22
            $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
32
        }
33
34
        // XML header
35 22
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');
36
37
        // xdr:wsDr
38 22
        $objWriter->startElement('xdr:wsDr');
39 22
        $objWriter->writeAttribute('xmlns:xdr', 'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing');
40 22
        $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
41
42
        // Loop through images and write drawings
43 22
        $i = 1;
44 22
        $iterator = $pWorksheet->getDrawingCollection()->getIterator();
45 22
        while ($iterator->valid()) {
46 10
            $this->writeDrawing($objWriter, $iterator->current(), $i);
47
48 10
            $iterator->next();
49 10
            ++$i;
50
        }
51
52 22
        if ($includeCharts) {
53 13
            $chartCount = $pWorksheet->getChartCount();
54
            // Loop through charts and write the chart position
55 13
            if ($chartCount > 0) {
56 13
                for ($c = 0; $c < $chartCount; ++$c) {
57 13
                    $this->writeChart($objWriter, $pWorksheet->getChartByIndex($c), $c + $i);
1 ignored issue
show
Bug introduced by
It seems like $pWorksheet->getChartByIndex($c) can also be of type false; however, parameter $pChart of PhpOffice\PhpSpreadsheet...x\Drawing::writeChart() does only seem to accept PhpOffice\PhpSpreadsheet\Chart\Chart, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
                    $this->writeChart($objWriter, /** @scrutinizer ignore-type */ $pWorksheet->getChartByIndex($c), $c + $i);
Loading history...
58
                }
59
            }
60
        }
61
62 22
        $objWriter->endElement();
63
64
        // Return
65 22
        return $objWriter->getData();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $objWriter->getData() could also return false which is incompatible with the documented return type string. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
66
    }
67
68
    /**
69
     * Write drawings to XML format.
70
     *
71
     * @param XMLWriter $objWriter XML Writer
72
     * @param \PhpOffice\PhpSpreadsheet\Chart\Chart $pChart
73
     * @param int $pRelationId
74
     *
75
     * @throws WriterException
76
     */
77 13
    public function writeChart(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Chart\Chart $pChart, $pRelationId = -1)
78
    {
79 13
        $tl = $pChart->getTopLeftPosition();
80 13
        $tl['colRow'] = Coordinate::coordinateFromString($tl['cell']);
81 13
        $br = $pChart->getBottomRightPosition();
82 13
        $br['colRow'] = Coordinate::coordinateFromString($br['cell']);
83
84 13
        $objWriter->startElement('xdr:twoCellAnchor');
85
86 13
        $objWriter->startElement('xdr:from');
87 13
        $objWriter->writeElement('xdr:col', Coordinate::columnIndexFromString($tl['colRow'][0]) - 1);
88 13
        $objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($tl['xOffset']));
1 ignored issue
show
Bug introduced by
It seems like $tl['xOffset'] can also be of type string[] and string[]; however, parameter $pValue of PhpOffice\PhpSpreadsheet...\Drawing::pixelsToEMU() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

88
        $objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU(/** @scrutinizer ignore-type */ $tl['xOffset']));
Loading history...
89 13
        $objWriter->writeElement('xdr:row', $tl['colRow'][1] - 1);
90 13
        $objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($tl['yOffset']));
91 13
        $objWriter->endElement();
92 13
        $objWriter->startElement('xdr:to');
93 13
        $objWriter->writeElement('xdr:col', Coordinate::columnIndexFromString($br['colRow'][0]) - 1);
94 13
        $objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($br['xOffset']));
95 13
        $objWriter->writeElement('xdr:row', $br['colRow'][1] - 1);
96 13
        $objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($br['yOffset']));
97 13
        $objWriter->endElement();
98
99 13
        $objWriter->startElement('xdr:graphicFrame');
100 13
        $objWriter->writeAttribute('macro', '');
101 13
        $objWriter->startElement('xdr:nvGraphicFramePr');
102 13
        $objWriter->startElement('xdr:cNvPr');
103 13
        $objWriter->writeAttribute('name', 'Chart ' . $pRelationId);
104 13
        $objWriter->writeAttribute('id', 1025 * $pRelationId);
105 13
        $objWriter->endElement();
106 13
        $objWriter->startElement('xdr:cNvGraphicFramePr');
107 13
        $objWriter->startElement('a:graphicFrameLocks');
108 13
        $objWriter->endElement();
109 13
        $objWriter->endElement();
110 13
        $objWriter->endElement();
111
112 13
        $objWriter->startElement('xdr:xfrm');
113 13
        $objWriter->startElement('a:off');
114 13
        $objWriter->writeAttribute('x', '0');
115 13
        $objWriter->writeAttribute('y', '0');
116 13
        $objWriter->endElement();
117 13
        $objWriter->startElement('a:ext');
118 13
        $objWriter->writeAttribute('cx', '0');
119 13
        $objWriter->writeAttribute('cy', '0');
120 13
        $objWriter->endElement();
121 13
        $objWriter->endElement();
122
123 13
        $objWriter->startElement('a:graphic');
124 13
        $objWriter->startElement('a:graphicData');
125 13
        $objWriter->writeAttribute('uri', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
126 13
        $objWriter->startElement('c:chart');
127 13
        $objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart');
128 13
        $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
129 13
        $objWriter->writeAttribute('r:id', 'rId' . $pRelationId);
130 13
        $objWriter->endElement();
131 13
        $objWriter->endElement();
132 13
        $objWriter->endElement();
133 13
        $objWriter->endElement();
134
135 13
        $objWriter->startElement('xdr:clientData');
136 13
        $objWriter->endElement();
137
138 13
        $objWriter->endElement();
139 13
    }
140
141
    /**
142
     * Write drawings to XML format.
143
     *
144
     * @param XMLWriter $objWriter XML Writer
145
     * @param BaseDrawing $pDrawing
146
     * @param int $pRelationId
147
     *
148
     * @throws WriterException
149
     */
150 10
    public function writeDrawing(XMLWriter $objWriter, BaseDrawing $pDrawing, $pRelationId = -1)
151
    {
152 10
        if ($pRelationId >= 0) {
153
            // xdr:oneCellAnchor
154 10
            $objWriter->startElement('xdr:oneCellAnchor');
155
            // Image location
156 10
            $aCoordinates = Coordinate::coordinateFromString($pDrawing->getCoordinates());
157 10
            $aCoordinates[0] = Coordinate::columnIndexFromString($aCoordinates[0]);
158
159
            // xdr:from
160 10
            $objWriter->startElement('xdr:from');
161 10
            $objWriter->writeElement('xdr:col', $aCoordinates[0] - 1);
162 10
            $objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getOffsetX()));
163 10
            $objWriter->writeElement('xdr:row', $aCoordinates[1] - 1);
164 10
            $objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getOffsetY()));
165 10
            $objWriter->endElement();
166
167
            // xdr:ext
168 10
            $objWriter->startElement('xdr:ext');
169 10
            $objWriter->writeAttribute('cx', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getWidth()));
170 10
            $objWriter->writeAttribute('cy', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getHeight()));
171 10
            $objWriter->endElement();
172
173
            // xdr:pic
174 10
            $objWriter->startElement('xdr:pic');
175
176
            // xdr:nvPicPr
177 10
            $objWriter->startElement('xdr:nvPicPr');
178
179
            // xdr:cNvPr
180 10
            $objWriter->startElement('xdr:cNvPr');
181 10
            $objWriter->writeAttribute('id', $pRelationId);
182 10
            $objWriter->writeAttribute('name', $pDrawing->getName());
183 10
            $objWriter->writeAttribute('descr', $pDrawing->getDescription());
184 10
            $objWriter->endElement();
185
186
            // xdr:cNvPicPr
187 10
            $objWriter->startElement('xdr:cNvPicPr');
188
189
            // a:picLocks
190 10
            $objWriter->startElement('a:picLocks');
191 10
            $objWriter->writeAttribute('noChangeAspect', '1');
192 10
            $objWriter->endElement();
193
194 10
            $objWriter->endElement();
195
196 10
            $objWriter->endElement();
197
198
            // xdr:blipFill
199 10
            $objWriter->startElement('xdr:blipFill');
200
201
            // a:blip
202 10
            $objWriter->startElement('a:blip');
203 10
            $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
204 10
            $objWriter->writeAttribute('r:embed', 'rId' . $pRelationId);
205 10
            $objWriter->endElement();
206
207
            // a:stretch
208 10
            $objWriter->startElement('a:stretch');
209 10
            $objWriter->writeElement('a:fillRect', null);
210 10
            $objWriter->endElement();
211
212 10
            $objWriter->endElement();
213
214
            // xdr:spPr
215 10
            $objWriter->startElement('xdr:spPr');
216
217
            // a:xfrm
218 10
            $objWriter->startElement('a:xfrm');
219 10
            $objWriter->writeAttribute('rot', \PhpOffice\PhpSpreadsheet\Shared\Drawing::degreesToAngle($pDrawing->getRotation()));
220 10
            $objWriter->endElement();
221
222
            // a:prstGeom
223 10
            $objWriter->startElement('a:prstGeom');
224 10
            $objWriter->writeAttribute('prst', 'rect');
225
226
            // a:avLst
227 10
            $objWriter->writeElement('a:avLst', null);
228
229 10
            $objWriter->endElement();
230
231 10
            if ($pDrawing->getShadow()->getVisible()) {
232
                // a:effectLst
233 5
                $objWriter->startElement('a:effectLst');
234
235
                // a:outerShdw
236 5
                $objWriter->startElement('a:outerShdw');
237 5
                $objWriter->writeAttribute('blurRad', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getShadow()->getBlurRadius()));
238 5
                $objWriter->writeAttribute('dist', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($pDrawing->getShadow()->getDistance()));
239 5
                $objWriter->writeAttribute('dir', \PhpOffice\PhpSpreadsheet\Shared\Drawing::degreesToAngle($pDrawing->getShadow()->getDirection()));
240 5
                $objWriter->writeAttribute('algn', $pDrawing->getShadow()->getAlignment());
241 5
                $objWriter->writeAttribute('rotWithShape', '0');
242
243
                // a:srgbClr
244 5
                $objWriter->startElement('a:srgbClr');
245 5
                $objWriter->writeAttribute('val', $pDrawing->getShadow()->getColor()->getRGB());
246
247
                // a:alpha
248 5
                $objWriter->startElement('a:alpha');
249 5
                $objWriter->writeAttribute('val', $pDrawing->getShadow()->getAlpha() * 1000);
250 5
                $objWriter->endElement();
251
252 5
                $objWriter->endElement();
253
254 5
                $objWriter->endElement();
255
256 5
                $objWriter->endElement();
257
            }
258 10
            $objWriter->endElement();
259
260 10
            $objWriter->endElement();
261
262
            // xdr:clientData
263 10
            $objWriter->writeElement('xdr:clientData', null);
264
265 10
            $objWriter->endElement();
266
        } else {
267
            throw new WriterException('Invalid parameters passed.');
268
        }
269 10
    }
270
271
    /**
272
     * Write VML header/footer images to XML format.
273
     *
274
     * @param \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet
275
     *
276
     * @throws WriterException
277
     *
278
     * @return string XML Output
279
     */
280 1
    public function writeVMLHeaderFooterImages(\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $pWorksheet)
281
    {
282
        // Create XML writer
283 1
        $objWriter = null;
284 1 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...
285
            $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
286
        } else {
287 1
            $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
288
        }
289
290
        // XML header
291 1
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');
292
293
        // Header/footer images
294 1
        $images = $pWorksheet->getHeaderFooter()->getImages();
295
296
        // xml
297 1
        $objWriter->startElement('xml');
298 1
        $objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
299 1
        $objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
300 1
        $objWriter->writeAttribute('xmlns:x', 'urn:schemas-microsoft-com:office:excel');
301
302
        // o:shapelayout
303 1
        $objWriter->startElement('o:shapelayout');
304 1
        $objWriter->writeAttribute('v:ext', 'edit');
305
306
        // o:idmap
307 1
        $objWriter->startElement('o:idmap');
308 1
        $objWriter->writeAttribute('v:ext', 'edit');
309 1
        $objWriter->writeAttribute('data', '1');
310 1
        $objWriter->endElement();
311
312 1
        $objWriter->endElement();
313
314
        // v:shapetype
315 1
        $objWriter->startElement('v:shapetype');
316 1
        $objWriter->writeAttribute('id', '_x0000_t75');
317 1
        $objWriter->writeAttribute('coordsize', '21600,21600');
318 1
        $objWriter->writeAttribute('o:spt', '75');
319 1
        $objWriter->writeAttribute('o:preferrelative', 't');
320 1
        $objWriter->writeAttribute('path', 'm@4@5l@4@11@9@11@9@5xe');
321 1
        $objWriter->writeAttribute('filled', 'f');
322 1
        $objWriter->writeAttribute('stroked', 'f');
323
324
        // v:stroke
325 1
        $objWriter->startElement('v:stroke');
326 1
        $objWriter->writeAttribute('joinstyle', 'miter');
327 1
        $objWriter->endElement();
328
329
        // v:formulas
330 1
        $objWriter->startElement('v:formulas');
331
332
        // v:f
333 1
        $objWriter->startElement('v:f');
334 1
        $objWriter->writeAttribute('eqn', 'if lineDrawn pixelLineWidth 0');
335 1
        $objWriter->endElement();
336
337
        // v:f
338 1
        $objWriter->startElement('v:f');
339 1
        $objWriter->writeAttribute('eqn', 'sum @0 1 0');
340 1
        $objWriter->endElement();
341
342
        // v:f
343 1
        $objWriter->startElement('v:f');
344 1
        $objWriter->writeAttribute('eqn', 'sum 0 0 @1');
345 1
        $objWriter->endElement();
346
347
        // v:f
348 1
        $objWriter->startElement('v:f');
349 1
        $objWriter->writeAttribute('eqn', 'prod @2 1 2');
350 1
        $objWriter->endElement();
351
352
        // v:f
353 1
        $objWriter->startElement('v:f');
354 1
        $objWriter->writeAttribute('eqn', 'prod @3 21600 pixelWidth');
355 1
        $objWriter->endElement();
356
357
        // v:f
358 1
        $objWriter->startElement('v:f');
359 1
        $objWriter->writeAttribute('eqn', 'prod @3 21600 pixelHeight');
360 1
        $objWriter->endElement();
361
362
        // v:f
363 1
        $objWriter->startElement('v:f');
364 1
        $objWriter->writeAttribute('eqn', 'sum @0 0 1');
365 1
        $objWriter->endElement();
366
367
        // v:f
368 1
        $objWriter->startElement('v:f');
369 1
        $objWriter->writeAttribute('eqn', 'prod @6 1 2');
370 1
        $objWriter->endElement();
371
372
        // v:f
373 1
        $objWriter->startElement('v:f');
374 1
        $objWriter->writeAttribute('eqn', 'prod @7 21600 pixelWidth');
375 1
        $objWriter->endElement();
376
377
        // v:f
378 1
        $objWriter->startElement('v:f');
379 1
        $objWriter->writeAttribute('eqn', 'sum @8 21600 0');
380 1
        $objWriter->endElement();
381
382
        // v:f
383 1
        $objWriter->startElement('v:f');
384 1
        $objWriter->writeAttribute('eqn', 'prod @7 21600 pixelHeight');
385 1
        $objWriter->endElement();
386
387
        // v:f
388 1
        $objWriter->startElement('v:f');
389 1
        $objWriter->writeAttribute('eqn', 'sum @10 21600 0');
390 1
        $objWriter->endElement();
391
392 1
        $objWriter->endElement();
393
394
        // v:path
395 1
        $objWriter->startElement('v:path');
396 1
        $objWriter->writeAttribute('o:extrusionok', 'f');
397 1
        $objWriter->writeAttribute('gradientshapeok', 't');
398 1
        $objWriter->writeAttribute('o:connecttype', 'rect');
399 1
        $objWriter->endElement();
400
401
        // o:lock
402 1
        $objWriter->startElement('o:lock');
403 1
        $objWriter->writeAttribute('v:ext', 'edit');
404 1
        $objWriter->writeAttribute('aspectratio', 't');
405 1
        $objWriter->endElement();
406
407 1
        $objWriter->endElement();
408
409
        // Loop through images
410 1
        foreach ($images as $key => $value) {
411 1
            $this->writeVMLHeaderFooterImage($objWriter, $key, $value);
412
        }
413
414 1
        $objWriter->endElement();
415
416
        // Return
417 1
        return $objWriter->getData();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $objWriter->getData() could also return false which is incompatible with the documented return type string. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
418
    }
419
420
    /**
421
     * Write VML comment to XML format.
422
     *
423
     * @param XMLWriter $objWriter XML Writer
424
     * @param string $pReference Reference
425
     * @param HeaderFooterDrawing $pImage Image
426
     *
427
     * @throws WriterException
428
     */
429 1
    private function writeVMLHeaderFooterImage(XMLWriter $objWriter, $pReference, HeaderFooterDrawing $pImage)
430
    {
431
        // Calculate object id
432 1
        preg_match('{(\d+)}', md5($pReference), $m);
433 1
        $id = 1500 + (substr($m[1], 0, 2) * 1);
434
435
        // Calculate offset
436 1
        $width = $pImage->getWidth();
437 1
        $height = $pImage->getHeight();
438 1
        $marginLeft = $pImage->getOffsetX();
439 1
        $marginTop = $pImage->getOffsetY();
440
441
        // v:shape
442 1
        $objWriter->startElement('v:shape');
443 1
        $objWriter->writeAttribute('id', $pReference);
444 1
        $objWriter->writeAttribute('o:spid', '_x0000_s' . $id);
445 1
        $objWriter->writeAttribute('type', '#_x0000_t75');
446 1
        $objWriter->writeAttribute('style', "position:absolute;margin-left:{$marginLeft}px;margin-top:{$marginTop}px;width:{$width}px;height:{$height}px;z-index:1");
447
448
        // v:imagedata
449 1
        $objWriter->startElement('v:imagedata');
450 1
        $objWriter->writeAttribute('o:relid', 'rId' . $pReference);
451 1
        $objWriter->writeAttribute('o:title', $pImage->getName());
452 1
        $objWriter->endElement();
453
454
        // o:lock
455 1
        $objWriter->startElement('o:lock');
456 1
        $objWriter->writeAttribute('v:ext', 'edit');
457 1
        $objWriter->writeAttribute('textRotation', 't');
458 1
        $objWriter->endElement();
459
460 1
        $objWriter->endElement();
461 1
    }
462
463
    /**
464
     * Get an array of all drawings.
465
     *
466
     * @param Spreadsheet $spreadsheet
467
     *
468
     * @throws WriterException
469
     *
470
     * @return \PhpOffice\PhpSpreadsheet\Worksheet\Drawing[] All drawings in PhpSpreadsheet
471
     */
472 56
    public function allDrawings(Spreadsheet $spreadsheet)
473
    {
474
        // Get an array of all drawings
475 56
        $aDrawings = [];
476
477
        // Loop through PhpSpreadsheet
478 56
        $sheetCount = $spreadsheet->getSheetCount();
479 56
        for ($i = 0; $i < $sheetCount; ++$i) {
480
            // Loop through images and add to array
481 56
            $iterator = $spreadsheet->getSheet($i)->getDrawingCollection()->getIterator();
482 56
            while ($iterator->valid()) {
483 10
                $aDrawings[] = $iterator->current();
484
485 10
                $iterator->next();
486
            }
487
        }
488
489 56
        return $aDrawings;
490
    }
491
}
492