Completed
Push — master ( 4b5c92...896769 )
by Adrien
16:06 queued 09:43
created

Xlsx::getDrawingHashTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Writer;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
6
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
7
use PhpOffice\PhpSpreadsheet\HashTable;
8
use PhpOffice\PhpSpreadsheet\Shared\File;
9
use PhpOffice\PhpSpreadsheet\Spreadsheet;
10
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing as WorksheetDrawing;
11
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing;
12
use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException;
13
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Chart;
14
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Comments;
15
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\ContentTypes;
16
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\DocProps;
17
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Drawing;
18
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Rels;
19
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\RelsRibbon;
20
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\RelsVBA;
21
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\StringTable;
22
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Style;
23
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Theme;
24
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Workbook;
25
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet;
26
use ZipArchive;
27
use ZipStream\Exception\OverflowException;
28
use ZipStream\Option\Archive;
29
use ZipStream\ZipStream;
30
31
class Xlsx extends BaseWriter
32
{
33
    /**
34
     * Office2003 compatibility.
35
     *
36
     * @var bool
37
     */
38
    private $office2003compatibility = false;
39
40
    /**
41
     * Private writer parts.
42
     *
43
     * @var Xlsx\WriterPart[]
44
     */
45
    private $writerParts = [];
46
47
    /**
48
     * Private Spreadsheet.
49
     *
50
     * @var Spreadsheet
51
     */
52
    private $spreadSheet;
53
54
    /**
55
     * Private string table.
56
     *
57
     * @var string[]
58
     */
59
    private $stringTable = [];
60
61
    /**
62
     * Private unique Conditional HashTable.
63
     *
64
     * @var HashTable
65
     */
66
    private $stylesConditionalHashTable;
67
68
    /**
69
     * Private unique Style HashTable.
70
     *
71
     * @var HashTable
72
     */
73
    private $styleHashTable;
74
75
    /**
76
     * Private unique Fill HashTable.
77
     *
78
     * @var HashTable
79
     */
80
    private $fillHashTable;
81
82
    /**
83
     * Private unique \PhpOffice\PhpSpreadsheet\Style\Font HashTable.
84
     *
85
     * @var HashTable
86
     */
87
    private $fontHashTable;
88
89
    /**
90
     * Private unique Borders HashTable.
91
     *
92
     * @var HashTable
93
     */
94
    private $bordersHashTable;
95
96
    /**
97
     * Private unique NumberFormat HashTable.
98
     *
99
     * @var HashTable
100
     */
101
    private $numFmtHashTable;
102
103
    /**
104
     * Private unique \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\BaseDrawing HashTable.
105
     *
106
     * @var HashTable
107
     */
108
    private $drawingHashTable;
109
110
    /**
111
     * Create a new Xlsx Writer.
112
     *
113
     * @param Spreadsheet $spreadsheet
114
     */
115 107
    public function __construct(Spreadsheet $spreadsheet)
116
    {
117
        // Assign PhpSpreadsheet
118 107
        $this->setSpreadsheet($spreadsheet);
119
120
        $writerPartsArray = [
121 107
            'stringtable' => StringTable::class,
122
            'contenttypes' => ContentTypes::class,
123
            'docprops' => DocProps::class,
124
            'rels' => Rels::class,
125
            'theme' => Theme::class,
126
            'style' => Style::class,
127
            'workbook' => Workbook::class,
128
            'worksheet' => Worksheet::class,
129
            'drawing' => Drawing::class,
130
            'comments' => Comments::class,
131
            'chart' => Chart::class,
132
            'relsvba' => RelsVBA::class,
133
            'relsribbonobjects' => RelsRibbon::class,
134
        ];
135
136
        //    Initialise writer parts
137
        //        and Assign their parent IWriters
138 107
        foreach ($writerPartsArray as $writer => $class) {
139 107
            $this->writerParts[$writer] = new $class($this);
140
        }
141
142 107
        $hashTablesArray = ['stylesConditionalHashTable', 'fillHashTable', 'fontHashTable',
143
            'bordersHashTable', 'numFmtHashTable', 'drawingHashTable',
144
            'styleHashTable',
145
        ];
146
147
        // Set HashTable variables
148 107
        foreach ($hashTablesArray as $tableName) {
149 107
            $this->$tableName = new HashTable();
150
        }
151 107
    }
152
153
    /**
154
     * Get writer part.
155
     *
156
     * @param string $pPartName Writer part name
157
     *
158
     * @return \PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart
159
     */
160 106
    public function getWriterPart($pPartName)
161
    {
162 106
        if ($pPartName != '' && isset($this->writerParts[strtolower($pPartName)])) {
163 106
            return $this->writerParts[strtolower($pPartName)];
164
        }
165
166
        return null;
167
    }
168
169
    /**
170
     * Save PhpSpreadsheet to file.
171
     *
172
     * @param resource|string $pFilename
173
     *
174
     * @throws WriterException
175
     */
176 106
    public function save($pFilename)
177
    {
178 106
        if ($this->spreadSheet !== null) {
179
            // garbage collect
180 106
            $this->spreadSheet->garbageCollect();
181
182 106
            $this->openFileHandle($pFilename);
183
184 106
            $saveDebugLog = Calculation::getInstance($this->spreadSheet)->getDebugLog()->getWriteDebugLog();
185 106
            Calculation::getInstance($this->spreadSheet)->getDebugLog()->setWriteDebugLog(false);
186 106
            $saveDateReturnType = Functions::getReturnDateType();
187 106
            Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
188
189
            // Create string lookup table
190 106
            $this->stringTable = [];
191 106
            for ($i = 0; $i < $this->spreadSheet->getSheetCount(); ++$i) {
192 106
                $this->stringTable = $this->getWriterPart('StringTable')->createStringTable($this->spreadSheet->getSheet($i), $this->stringTable);
0 ignored issues
show
Bug introduced by
The method createStringTable() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\StringTable. ( Ignorable by Annotation )

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

192
                $this->stringTable = $this->getWriterPart('StringTable')->/** @scrutinizer ignore-call */ createStringTable($this->spreadSheet->getSheet($i), $this->stringTable);
Loading history...
193
            }
194
195
            // Create styles dictionaries
196 106
            $this->styleHashTable->addFromSource($this->getWriterPart('Style')->allStyles($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method allStyles() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Style. ( Ignorable by Annotation )

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

196
            $this->styleHashTable->addFromSource($this->getWriterPart('Style')->/** @scrutinizer ignore-call */ allStyles($this->spreadSheet));
Loading history...
197 106
            $this->stylesConditionalHashTable->addFromSource($this->getWriterPart('Style')->allConditionalStyles($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method allConditionalStyles() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Style. ( Ignorable by Annotation )

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

197
            $this->stylesConditionalHashTable->addFromSource($this->getWriterPart('Style')->/** @scrutinizer ignore-call */ allConditionalStyles($this->spreadSheet));
Loading history...
198 106
            $this->fillHashTable->addFromSource($this->getWriterPart('Style')->allFills($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method allFills() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Style. ( Ignorable by Annotation )

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

198
            $this->fillHashTable->addFromSource($this->getWriterPart('Style')->/** @scrutinizer ignore-call */ allFills($this->spreadSheet));
Loading history...
199 106
            $this->fontHashTable->addFromSource($this->getWriterPart('Style')->allFonts($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method allFonts() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Style. ( Ignorable by Annotation )

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

199
            $this->fontHashTable->addFromSource($this->getWriterPart('Style')->/** @scrutinizer ignore-call */ allFonts($this->spreadSheet));
Loading history...
200 106
            $this->bordersHashTable->addFromSource($this->getWriterPart('Style')->allBorders($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method allBorders() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Style. ( Ignorable by Annotation )

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

200
            $this->bordersHashTable->addFromSource($this->getWriterPart('Style')->/** @scrutinizer ignore-call */ allBorders($this->spreadSheet));
Loading history...
201 106
            $this->numFmtHashTable->addFromSource($this->getWriterPart('Style')->allNumberFormats($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method allNumberFormats() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Style. ( Ignorable by Annotation )

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

201
            $this->numFmtHashTable->addFromSource($this->getWriterPart('Style')->/** @scrutinizer ignore-call */ allNumberFormats($this->spreadSheet));
Loading history...
202
203
            // Create drawing dictionary
204 106
            $this->drawingHashTable->addFromSource($this->getWriterPart('Drawing')->allDrawings($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method allDrawings() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Drawing. ( Ignorable by Annotation )

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

204
            $this->drawingHashTable->addFromSource($this->getWriterPart('Drawing')->/** @scrutinizer ignore-call */ allDrawings($this->spreadSheet));
Loading history...
205
206 106
            $options = new Archive();
207 106
            $options->setEnableZip64(false);
208 106
            $options->setOutputStream($this->fileHandle);
209
210 106
            $zip = new ZipStream(null, $options);
211
212
            // Add [Content_Types].xml to ZIP file
213 106
            $zip->addFile('[Content_Types].xml', $this->getWriterPart('ContentTypes')->writeContentTypes($this->spreadSheet, $this->includeCharts));
0 ignored issues
show
Bug introduced by
The method writeContentTypes() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\ContentTypes. ( Ignorable by Annotation )

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

213
            $zip->addFile('[Content_Types].xml', $this->getWriterPart('ContentTypes')->/** @scrutinizer ignore-call */ writeContentTypes($this->spreadSheet, $this->includeCharts));
Loading history...
214
215
            //if hasMacros, add the vbaProject.bin file, Certificate file(if exists)
216 106
            if ($this->spreadSheet->hasMacros()) {
217 1
                $macrosCode = $this->spreadSheet->getMacrosCode();
218 1
                if ($macrosCode !== null) {
0 ignored issues
show
introduced by
The condition $macrosCode !== null is always true.
Loading history...
219
                    // we have the code ?
220 1
                    $zip->addFile('xl/vbaProject.bin', $macrosCode); //allways in 'xl', allways named vbaProject.bin
221 1
                    if ($this->spreadSheet->hasMacrosCertificate()) {
222
                        //signed macros ?
223
                        // Yes : add the certificate file and the related rels file
224
                        $zip->addFile('xl/vbaProjectSignature.bin', $this->spreadSheet->getMacrosCertificate());
225
                        $zip->addFile('xl/_rels/vbaProject.bin.rels', $this->getWriterPart('RelsVBA')->writeVBARelationships($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method writeVBARelationships() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\RelsVBA. ( Ignorable by Annotation )

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

225
                        $zip->addFile('xl/_rels/vbaProject.bin.rels', $this->getWriterPart('RelsVBA')->/** @scrutinizer ignore-call */ writeVBARelationships($this->spreadSheet));
Loading history...
226
                    }
227
                }
228
            }
229
            //a custom UI in this workbook ? add it ("base" xml and additional objects (pictures) and rels)
230 106
            if ($this->spreadSheet->hasRibbon()) {
231
                $tmpRibbonTarget = $this->spreadSheet->getRibbonXMLData('target');
232
                $zip->addFile($tmpRibbonTarget, $this->spreadSheet->getRibbonXMLData('data'));
233
                if ($this->spreadSheet->hasRibbonBinObjects()) {
234
                    $tmpRootPath = dirname($tmpRibbonTarget) . '/';
235
                    $ribbonBinObjects = $this->spreadSheet->getRibbonBinObjects('data'); //the files to write
236
                    foreach ($ribbonBinObjects as $aPath => $aContent) {
237
                        $zip->addFile($tmpRootPath . $aPath, $aContent);
238
                    }
239
                    //the rels for files
240
                    $zip->addFile($tmpRootPath . '_rels/' . basename($tmpRibbonTarget) . '.rels', $this->getWriterPart('RelsRibbonObjects')->writeRibbonRelationships($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method writeRibbonRelationships() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\RelsRibbon. ( Ignorable by Annotation )

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

240
                    $zip->addFile($tmpRootPath . '_rels/' . basename($tmpRibbonTarget) . '.rels', $this->getWriterPart('RelsRibbonObjects')->/** @scrutinizer ignore-call */ writeRibbonRelationships($this->spreadSheet));
Loading history...
241
                }
242
            }
243
244
            // Add relationships to ZIP file
245 106
            $zip->addFile('_rels/.rels', $this->getWriterPart('Rels')->writeRelationships($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method writeRelationships() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Rels. ( Ignorable by Annotation )

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

245
            $zip->addFile('_rels/.rels', $this->getWriterPart('Rels')->/** @scrutinizer ignore-call */ writeRelationships($this->spreadSheet));
Loading history...
246 106
            $zip->addFile('xl/_rels/workbook.xml.rels', $this->getWriterPart('Rels')->writeWorkbookRelationships($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method writeWorkbookRelationships() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Rels. ( Ignorable by Annotation )

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

246
            $zip->addFile('xl/_rels/workbook.xml.rels', $this->getWriterPart('Rels')->/** @scrutinizer ignore-call */ writeWorkbookRelationships($this->spreadSheet));
Loading history...
247
248
            // Add document properties to ZIP file
249 106
            $zip->addFile('docProps/app.xml', $this->getWriterPart('DocProps')->writeDocPropsApp($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method writeDocPropsApp() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\DocProps. ( Ignorable by Annotation )

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

249
            $zip->addFile('docProps/app.xml', $this->getWriterPart('DocProps')->/** @scrutinizer ignore-call */ writeDocPropsApp($this->spreadSheet));
Loading history...
250 106
            $zip->addFile('docProps/core.xml', $this->getWriterPart('DocProps')->writeDocPropsCore($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method writeDocPropsCore() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\DocProps. ( Ignorable by Annotation )

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

250
            $zip->addFile('docProps/core.xml', $this->getWriterPart('DocProps')->/** @scrutinizer ignore-call */ writeDocPropsCore($this->spreadSheet));
Loading history...
251 106
            $customPropertiesPart = $this->getWriterPart('DocProps')->writeDocPropsCustom($this->spreadSheet);
0 ignored issues
show
Bug introduced by
The method writeDocPropsCustom() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\DocProps. ( Ignorable by Annotation )

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

251
            $customPropertiesPart = $this->getWriterPart('DocProps')->/** @scrutinizer ignore-call */ writeDocPropsCustom($this->spreadSheet);
Loading history...
252 106
            if ($customPropertiesPart !== null) {
253 2
                $zip->addFile('docProps/custom.xml', $customPropertiesPart);
254
            }
255
256
            // Add theme to ZIP file
257 106
            $zip->addFile('xl/theme/theme1.xml', $this->getWriterPart('Theme')->writeTheme($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method writeTheme() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Theme. ( Ignorable by Annotation )

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

257
            $zip->addFile('xl/theme/theme1.xml', $this->getWriterPart('Theme')->/** @scrutinizer ignore-call */ writeTheme($this->spreadSheet));
Loading history...
258
259
            // Add string table to ZIP file
260 106
            $zip->addFile('xl/sharedStrings.xml', $this->getWriterPart('StringTable')->writeStringTable($this->stringTable));
0 ignored issues
show
Bug introduced by
The method writeStringTable() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\StringTable. ( Ignorable by Annotation )

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

260
            $zip->addFile('xl/sharedStrings.xml', $this->getWriterPart('StringTable')->/** @scrutinizer ignore-call */ writeStringTable($this->stringTable));
Loading history...
261
262
            // Add styles to ZIP file
263 106
            $zip->addFile('xl/styles.xml', $this->getWriterPart('Style')->writeStyles($this->spreadSheet));
0 ignored issues
show
Bug introduced by
The method writeStyles() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Style. ( Ignorable by Annotation )

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

263
            $zip->addFile('xl/styles.xml', $this->getWriterPart('Style')->/** @scrutinizer ignore-call */ writeStyles($this->spreadSheet));
Loading history...
264
265
            // Add workbook to ZIP file
266 106
            $zip->addFile('xl/workbook.xml', $this->getWriterPart('Workbook')->writeWorkbook($this->spreadSheet, $this->preCalculateFormulas));
0 ignored issues
show
Bug introduced by
The method writeWorkbook() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Workbook. ( Ignorable by Annotation )

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

266
            $zip->addFile('xl/workbook.xml', $this->getWriterPart('Workbook')->/** @scrutinizer ignore-call */ writeWorkbook($this->spreadSheet, $this->preCalculateFormulas));
Loading history...
267
268 106
            $chartCount = 0;
269
            // Add worksheets
270 106
            for ($i = 0; $i < $this->spreadSheet->getSheetCount(); ++$i) {
271 106
                $zip->addFile('xl/worksheets/sheet' . ($i + 1) . '.xml', $this->getWriterPart('Worksheet')->writeWorksheet($this->spreadSheet->getSheet($i), $this->stringTable, $this->includeCharts));
0 ignored issues
show
Bug introduced by
The method writeWorksheet() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet. ( Ignorable by Annotation )

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

271
                $zip->addFile('xl/worksheets/sheet' . ($i + 1) . '.xml', $this->getWriterPart('Worksheet')->/** @scrutinizer ignore-call */ writeWorksheet($this->spreadSheet->getSheet($i), $this->stringTable, $this->includeCharts));
Loading history...
272 106
                if ($this->includeCharts) {
273 15
                    $charts = $this->spreadSheet->getSheet($i)->getChartCollection();
274 15
                    if (count($charts) > 0) {
275 14
                        foreach ($charts as $chart) {
276 14
                            $zip->addFile('xl/charts/chart' . ($chartCount + 1) . '.xml', $this->getWriterPart('Chart')->writeChart($chart, $this->preCalculateFormulas));
0 ignored issues
show
Bug introduced by
The method writeChart() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Chart or PhpOffice\PhpSpreadsheet\Writer\Xlsx\Drawing. ( Ignorable by Annotation )

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

276
                            $zip->addFile('xl/charts/chart' . ($chartCount + 1) . '.xml', $this->getWriterPart('Chart')->/** @scrutinizer ignore-call */ writeChart($chart, $this->preCalculateFormulas));
Loading history...
277 14
                            ++$chartCount;
278
                        }
279
                    }
280
                }
281
            }
282
283 106
            $chartRef1 = 0;
284
            // Add worksheet relationships (drawings, ...)
285 106
            for ($i = 0; $i < $this->spreadSheet->getSheetCount(); ++$i) {
286
                // Add relationships
287 106
                $zip->addFile('xl/worksheets/_rels/sheet' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeWorksheetRelationships($this->spreadSheet->getSheet($i), ($i + 1), $this->includeCharts));
0 ignored issues
show
Bug introduced by
The method writeWorksheetRelationships() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Rels. ( Ignorable by Annotation )

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

287
                $zip->addFile('xl/worksheets/_rels/sheet' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->/** @scrutinizer ignore-call */ writeWorksheetRelationships($this->spreadSheet->getSheet($i), ($i + 1), $this->includeCharts));
Loading history...
288
289
                // Add unparsedLoadedData
290 106
                $sheetCodeName = $this->spreadSheet->getSheet($i)->getCodeName();
291 106
                $unparsedLoadedData = $this->spreadSheet->getUnparsedLoadedData();
292 106
                if (isset($unparsedLoadedData['sheets'][$sheetCodeName]['ctrlProps'])) {
293 1
                    foreach ($unparsedLoadedData['sheets'][$sheetCodeName]['ctrlProps'] as $ctrlProp) {
294 1
                        $zip->addFile($ctrlProp['filePath'], $ctrlProp['content']);
295
                    }
296
                }
297 106
                if (isset($unparsedLoadedData['sheets'][$sheetCodeName]['printerSettings'])) {
298 4
                    foreach ($unparsedLoadedData['sheets'][$sheetCodeName]['printerSettings'] as $ctrlProp) {
299 4
                        $zip->addFile($ctrlProp['filePath'], $ctrlProp['content']);
300
                    }
301
                }
302
303 106
                $drawings = $this->spreadSheet->getSheet($i)->getDrawingCollection();
304 106
                $drawingCount = count($drawings);
305 106
                if ($this->includeCharts) {
306 15
                    $chartCount = $this->spreadSheet->getSheet($i)->getChartCount();
307
                }
308
309
                // Add drawing and image relationship parts
310 106
                if (($drawingCount > 0) || ($chartCount > 0)) {
311
                    // Drawing relationships
312 25
                    $zip->addFile('xl/drawings/_rels/drawing' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeDrawingRelationships($this->spreadSheet->getSheet($i), $chartRef1, $this->includeCharts));
0 ignored issues
show
Bug introduced by
The method writeDrawingRelationships() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Rels. ( Ignorable by Annotation )

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

312
                    $zip->addFile('xl/drawings/_rels/drawing' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->/** @scrutinizer ignore-call */ writeDrawingRelationships($this->spreadSheet->getSheet($i), $chartRef1, $this->includeCharts));
Loading history...
313
314
                    // Drawings
315 25
                    $zip->addFile('xl/drawings/drawing' . ($i + 1) . '.xml', $this->getWriterPart('Drawing')->writeDrawings($this->spreadSheet->getSheet($i), $this->includeCharts));
0 ignored issues
show
Bug introduced by
The method writeDrawings() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Drawing or PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet. ( Ignorable by Annotation )

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

315
                    $zip->addFile('xl/drawings/drawing' . ($i + 1) . '.xml', $this->getWriterPart('Drawing')->/** @scrutinizer ignore-call */ writeDrawings($this->spreadSheet->getSheet($i), $this->includeCharts));
Loading history...
316 82
                } elseif (isset($unparsedLoadedData['sheets'][$sheetCodeName]['drawingAlternateContents'])) {
317
                    // Drawings
318 1
                    $zip->addFile('xl/drawings/drawing' . ($i + 1) . '.xml', $this->getWriterPart('Drawing')->writeDrawings($this->spreadSheet->getSheet($i), $this->includeCharts));
319
                }
320
321
                // Add unparsed drawings
322 106
                if (isset($unparsedLoadedData['sheets'][$sheetCodeName]['Drawings'])) {
323 2
                    foreach ($unparsedLoadedData['sheets'][$sheetCodeName]['Drawings'] as $relId => $drawingXml) {
324 2
                        $drawingFile = array_search($relId, $unparsedLoadedData['sheets'][$sheetCodeName]['drawingOriginalIds']);
325 2
                        if ($drawingFile !== false) {
326 2
                            $drawingFile = ltrim($drawingFile, '.');
327 2
                            $zip->addFile('xl' . $drawingFile, $drawingXml);
328
                        }
329
                    }
330
                }
331
332
                // Add comment relationship parts
333 106
                if (count($this->spreadSheet->getSheet($i)->getComments()) > 0) {
334
                    // VML Comments
335 10
                    $zip->addFile('xl/drawings/vmlDrawing' . ($i + 1) . '.vml', $this->getWriterPart('Comments')->writeVMLComments($this->spreadSheet->getSheet($i)));
0 ignored issues
show
Bug introduced by
The method writeVMLComments() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Comments. ( Ignorable by Annotation )

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

335
                    $zip->addFile('xl/drawings/vmlDrawing' . ($i + 1) . '.vml', $this->getWriterPart('Comments')->/** @scrutinizer ignore-call */ writeVMLComments($this->spreadSheet->getSheet($i)));
Loading history...
336
337
                    // Comments
338 10
                    $zip->addFile('xl/comments' . ($i + 1) . '.xml', $this->getWriterPart('Comments')->writeComments($this->spreadSheet->getSheet($i)));
0 ignored issues
show
Bug introduced by
The method writeComments() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Comments. ( Ignorable by Annotation )

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

338
                    $zip->addFile('xl/comments' . ($i + 1) . '.xml', $this->getWriterPart('Comments')->/** @scrutinizer ignore-call */ writeComments($this->spreadSheet->getSheet($i)));
Loading history...
339
                }
340
341
                // Add unparsed relationship parts
342 106
                if (isset($unparsedLoadedData['sheets'][$sheetCodeName]['vmlDrawings'])) {
343 1
                    foreach ($unparsedLoadedData['sheets'][$sheetCodeName]['vmlDrawings'] as $vmlDrawing) {
344 1
                        $zip->addFile($vmlDrawing['filePath'], $vmlDrawing['content']);
345
                    }
346
                }
347
348
                // Add header/footer relationship parts
349 106
                if (count($this->spreadSheet->getSheet($i)->getHeaderFooter()->getImages()) > 0) {
350
                    // VML Drawings
351 1
                    $zip->addFile('xl/drawings/vmlDrawingHF' . ($i + 1) . '.vml', $this->getWriterPart('Drawing')->writeVMLHeaderFooterImages($this->spreadSheet->getSheet($i)));
0 ignored issues
show
Bug introduced by
The method writeVMLHeaderFooterImages() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Drawing. ( Ignorable by Annotation )

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

351
                    $zip->addFile('xl/drawings/vmlDrawingHF' . ($i + 1) . '.vml', $this->getWriterPart('Drawing')->/** @scrutinizer ignore-call */ writeVMLHeaderFooterImages($this->spreadSheet->getSheet($i)));
Loading history...
352
353
                    // VML Drawing relationships
354 1
                    $zip->addFile('xl/drawings/_rels/vmlDrawingHF' . ($i + 1) . '.vml.rels', $this->getWriterPart('Rels')->writeHeaderFooterDrawingRelationships($this->spreadSheet->getSheet($i)));
0 ignored issues
show
Bug introduced by
The method writeHeaderFooterDrawingRelationships() does not exist on PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\Writer\Xlsx\WriterPart such as PhpOffice\PhpSpreadsheet\Writer\Xlsx\Rels. ( Ignorable by Annotation )

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

354
                    $zip->addFile('xl/drawings/_rels/vmlDrawingHF' . ($i + 1) . '.vml.rels', $this->getWriterPart('Rels')->/** @scrutinizer ignore-call */ writeHeaderFooterDrawingRelationships($this->spreadSheet->getSheet($i)));
Loading history...
355
356
                    // Media
357 1
                    foreach ($this->spreadSheet->getSheet($i)->getHeaderFooter()->getImages() as $image) {
358 1
                        $zip->addFile('xl/media/' . $image->getIndexedFilename(), file_get_contents($image->getPath()));
359
                    }
360
                }
361
            }
362
363
            // Add media
364 106
            for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
365 12
                if ($this->getDrawingHashTable()->getByIndex($i) instanceof WorksheetDrawing) {
366 6
                    $imageContents = null;
367 6
                    $imagePath = $this->getDrawingHashTable()->getByIndex($i)->getPath();
1 ignored issue
show
Bug introduced by
The method getPath() does not exist on PhpOffice\PhpSpreadsheet\IComparable. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\IComparable such as PhpOffice\PhpSpreadsheet\Worksheet\Drawing. ( Ignorable by Annotation )

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

367
                    $imagePath = $this->getDrawingHashTable()->getByIndex($i)->/** @scrutinizer ignore-call */ getPath();
Loading history...
368 6
                    if (strpos($imagePath, 'zip://') !== false) {
369 2
                        $imagePath = substr($imagePath, 6);
370 2
                        $imagePathSplitted = explode('#', $imagePath);
371
372 2
                        $imageZip = new ZipArchive();
373 2
                        $imageZip->open($imagePathSplitted[0]);
374 2
                        $imageContents = $imageZip->getFromName($imagePathSplitted[1]);
375 2
                        $imageZip->close();
376 2
                        unset($imageZip);
377
                    } else {
378 5
                        $imageContents = file_get_contents($imagePath);
379
                    }
380
381 6
                    $zip->addFile('xl/media/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
0 ignored issues
show
Bug introduced by
The method getIndexedFilename() does not exist on PhpOffice\PhpSpreadsheet\IComparable. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\IComparable such as PhpOffice\PhpSpreadsheet\Worksheet\Drawing or PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing. ( Ignorable by Annotation )

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

381
                    $zip->addFile('xl/media/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->/** @scrutinizer ignore-call */ getIndexedFilename()), $imageContents);
Loading history...
382 6
                } elseif ($this->getDrawingHashTable()->getByIndex($i) instanceof MemoryDrawing) {
383 6
                    ob_start();
384 6
                    call_user_func(
385 6
                        $this->getDrawingHashTable()->getByIndex($i)->getRenderingFunction(),
1 ignored issue
show
Bug introduced by
The method getRenderingFunction() does not exist on PhpOffice\PhpSpreadsheet\IComparable. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\IComparable such as PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing. ( Ignorable by Annotation )

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

385
                        $this->getDrawingHashTable()->getByIndex($i)->/** @scrutinizer ignore-call */ getRenderingFunction(),
Loading history...
386 6
                        $this->getDrawingHashTable()->getByIndex($i)->getImageResource()
1 ignored issue
show
Bug introduced by
The method getImageResource() does not exist on PhpOffice\PhpSpreadsheet\IComparable. It seems like you code against a sub-type of PhpOffice\PhpSpreadsheet\IComparable such as PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing. ( Ignorable by Annotation )

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

386
                        $this->getDrawingHashTable()->getByIndex($i)->/** @scrutinizer ignore-call */ getImageResource()
Loading history...
387
                    );
388 6
                    $imageContents = ob_get_contents();
389 6
                    ob_end_clean();
390
391 6
                    $zip->addFile('xl/media/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents);
392
                }
393
            }
394
395 106
            Functions::setReturnDateType($saveDateReturnType);
396 106
            Calculation::getInstance($this->spreadSheet)->getDebugLog()->setWriteDebugLog($saveDebugLog);
397
398
            // Close file
399
            try {
400 106
                $zip->finish();
401
            } catch (OverflowException $e) {
402
                throw new WriterException('Could not close resource.');
403
            }
404
405 106
            $this->maybeCloseFileHandle();
406
        } else {
407
            throw new WriterException('PhpSpreadsheet object unassigned.');
408
        }
409 106
    }
410
411
    /**
412
     * Get Spreadsheet object.
413
     *
414
     * @throws WriterException
415
     *
416
     * @return Spreadsheet
417
     */
418 106
    public function getSpreadsheet()
419
    {
420 106
        if ($this->spreadSheet !== null) {
421 106
            return $this->spreadSheet;
422
        }
423
424
        throw new WriterException('No Spreadsheet object assigned.');
425
    }
426
427
    /**
428
     * Set Spreadsheet object.
429
     *
430
     * @param Spreadsheet $spreadsheet PhpSpreadsheet object
431
     *
432
     * @return $this
433
     */
434 107
    public function setSpreadsheet(Spreadsheet $spreadsheet)
435
    {
436 107
        $this->spreadSheet = $spreadsheet;
437
438 107
        return $this;
439
    }
440
441
    /**
442
     * Get string table.
443
     *
444
     * @return string[]
445
     */
446
    public function getStringTable()
447
    {
448
        return $this->stringTable;
449
    }
450
451
    /**
452
     * Get Style HashTable.
453
     *
454
     * @return HashTable
455
     */
456
    public function getStyleHashTable()
457
    {
458
        return $this->styleHashTable;
459
    }
460
461
    /**
462
     * Get Conditional HashTable.
463
     *
464
     * @return HashTable
465
     */
466 106
    public function getStylesConditionalHashTable()
467
    {
468 106
        return $this->stylesConditionalHashTable;
469
    }
470
471
    /**
472
     * Get Fill HashTable.
473
     *
474
     * @return HashTable
475
     */
476 106
    public function getFillHashTable()
477
    {
478 106
        return $this->fillHashTable;
479
    }
480
481
    /**
482
     * Get \PhpOffice\PhpSpreadsheet\Style\Font HashTable.
483
     *
484
     * @return HashTable
485
     */
486 106
    public function getFontHashTable()
487
    {
488 106
        return $this->fontHashTable;
489
    }
490
491
    /**
492
     * Get Borders HashTable.
493
     *
494
     * @return HashTable
495
     */
496 106
    public function getBordersHashTable()
497
    {
498 106
        return $this->bordersHashTable;
499
    }
500
501
    /**
502
     * Get NumberFormat HashTable.
503
     *
504
     * @return HashTable
505
     */
506 106
    public function getNumFmtHashTable()
507
    {
508 106
        return $this->numFmtHashTable;
509
    }
510
511
    /**
512
     * Get \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\BaseDrawing HashTable.
513
     *
514
     * @return HashTable
515
     */
516 106
    public function getDrawingHashTable()
517
    {
518 106
        return $this->drawingHashTable;
519
    }
520
521
    /**
522
     * Get Office2003 compatibility.
523
     *
524
     * @return bool
525
     */
526 106
    public function getOffice2003Compatibility()
527
    {
528 106
        return $this->office2003compatibility;
529
    }
530
531
    /**
532
     * Set Office2003 compatibility.
533
     *
534
     * @param bool $pValue Office2003 compatibility?
535
     *
536
     * @return $this
537
     */
538
    public function setOffice2003Compatibility($pValue)
539
    {
540
        $this->office2003compatibility = $pValue;
541
542
        return $this;
543
    }
544
}
545