Skip to content

Commit 5b105de

Browse files
authored
Merge branch 'master' into Issue-3378_Improve-NumberFormat-Mask-Date-Identifier
2 parents 431bd51 + 1f94687 commit 5b105de

File tree

2 files changed

+21
-141
lines changed

2 files changed

+21
-141
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -199,103 +199,3 @@ parameters:
199199
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLERead\\:\\:\\$wrkbook has no type specified\\.$#"
200200
count: 1
201201
path: src/PhpSpreadsheet/Shared/OLERead.php
202-
203-
-
204-
message: "#^Cannot access offset 'comp' on array\\|false\\.$#"
205-
count: 1
206-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
207-
208-
-
209-
message: "#^Cannot access offset 'ident' on array\\|false\\.$#"
210-
count: 1
211-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
212-
213-
-
214-
message: "#^Cannot access offset 'sa' on array\\|false\\.$#"
215-
count: 1
216-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
217-
218-
-
219-
message: "#^Cannot access offset 1 on array\\|false\\.$#"
220-
count: 1
221-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
222-
223-
-
224-
message: "#^Cannot access offset 2 on array\\|false\\.$#"
225-
count: 2
226-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
227-
228-
-
229-
message: "#^Cannot call method getHashCode\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#"
230-
count: 1
231-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
232-
233-
-
234-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
235-
count: 1
236-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
237-
238-
-
239-
message: "#^Parameter \\#1 \\$string of function strlen expects string, string\\|false given\\.$#"
240-
count: 1
241-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
242-
243-
-
244-
message: "#^Parameter \\#1 \\$string of function substr expects string, string\\|false given\\.$#"
245-
count: 1
246-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
247-
248-
-
249-
message: "#^Parameter \\#2 \\$length of function fread expects int\\<0, max\\>, int\\<0, max\\>\\|false given\\.$#"
250-
count: 1
251-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
252-
253-
-
254-
message: "#^Parameter \\#4 \\$isError of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:writeBoolErr\\(\\) expects bool, int given\\.$#"
255-
count: 3
256-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
257-
258-
-
259-
message: "#^Parameter \\#5 \\$width of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:positionImage\\(\\) expects int, float given\\.$#"
260-
count: 1
261-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
262-
263-
-
264-
message: "#^Parameter \\#6 \\$height of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:positionImage\\(\\) expects int, float given\\.$#"
265-
count: 1
266-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
267-
268-
-
269-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:\\$activePane \\(int\\) does not accept int\\|null\\.$#"
270-
count: 1
271-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
272-
273-
-
274-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:\\$colors has no type specified\\.$#"
275-
count: 1
276-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
277-
278-
-
279-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:\\$countCellStyleXfs is never read, only written\\.$#"
280-
count: 1
281-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
282-
283-
-
284-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:\\$outlineBelow is never read, only written\\.$#"
285-
count: 1
286-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
287-
288-
-
289-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:\\$outlineRight is never read, only written\\.$#"
290-
count: 1
291-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
292-
293-
-
294-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:\\$selection is never read, only written\\.$#"
295-
count: 1
296-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
297-
298-
-
299-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:\\$xlsStringMaxLength is never read, only written\\.$#"
300-
count: 1
301-
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php

src/PhpSpreadsheet/Writer/Xls/Worksheet.php

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,13 @@ class Worksheet extends BIFFwriter
6868
*/
6969
private $parser;
7070

71-
/**
72-
* Maximum number of characters for a string (LABEL record in BIFF5).
73-
*
74-
* @var int
75-
*/
76-
private $xlsStringMaxLength;
77-
7871
/**
7972
* Array containing format information for columns.
8073
*
8174
* @var array
8275
*/
8376
private $columnInfo;
8477

85-
/**
86-
* Array containing the selected area for the worksheet.
87-
*
88-
* @var array
89-
*/
90-
private $selection;
91-
9278
/**
9379
* The active pane for the worksheet.
9480
*
@@ -112,17 +98,19 @@ class Worksheet extends BIFFwriter
11298

11399
/**
114100
* Whether to have outline summary below.
101+
* Not currently used.
115102
*
116103
* @var bool
117104
*/
118-
private $outlineBelow;
105+
private $outlineBelow; //* @phpstan-ignore-line
119106

120107
/**
121108
* Whether to have outline summary at the right.
109+
* Not currently used.
122110
*
123111
* @var bool
124112
*/
125-
private $outlineRight;
113+
private $outlineRight; //* @phpstan-ignore-line
126114

127115
/**
128116
* Reference to the total number of strings in the workbook.
@@ -147,6 +135,8 @@ class Worksheet extends BIFFwriter
147135

148136
/**
149137
* Color cache.
138+
*
139+
* @var array
150140
*/
151141
private $colors;
152142

@@ -185,13 +175,6 @@ class Worksheet extends BIFFwriter
185175
*/
186176
public $phpSheet;
187177

188-
/**
189-
* Count cell style Xfs.
190-
*
191-
* @var int
192-
*/
193-
private $countCellStyleXfs;
194-
195178
/**
196179
* Escher object corresponding to MSODRAWING.
197180
*
@@ -241,9 +224,7 @@ public function __construct(&$str_total, &$str_unique, &$str_table, &$colors, Pa
241224

242225
$this->phpSheet = $phpSheet;
243226

244-
$this->xlsStringMaxLength = 255;
245227
$this->columnInfo = [];
246-
$this->selection = [0, 0, 0, 0];
247228
$this->activePane = 3;
248229

249230
$this->printHeaders = 0;
@@ -272,8 +253,6 @@ public function __construct(&$str_total, &$str_unique, &$str_table, &$colors, Pa
272253
if ($this->lastColumnIndex > 255) {
273254
$this->lastColumnIndex = 255;
274255
}
275-
276-
$this->countCellStyleXfs = count($phpSheet->getParentOrThrow()->getCellStyleXfCollection());
277256
}
278257

279258
/**
@@ -428,10 +407,12 @@ public function close(): void
428407
$elements = $cVal->getRichTextElements();
429408
foreach ($elements as $element) {
430409
// FONT Index
410+
$str_fontidx = 0;
431411
if ($element instanceof Run) {
432-
$str_fontidx = $this->fontHashIndex[$element->getFont()->getHashCode()];
433-
} else {
434-
$str_fontidx = 0;
412+
$getFont = $element->getFont();
413+
if ($getFont !== null) {
414+
$str_fontidx = $this->fontHashIndex[$getFont->getHashCode()];
415+
}
435416
}
436417
$arrcRun[] = ['strlen' => $str_pos, 'fontidx' => $str_fontidx];
437418
// Position FROM
@@ -799,7 +780,7 @@ public function writeBlank($row, $col, $xfIndex)
799780
* @param int $row Row index (0-based)
800781
* @param int $col Column index (0-based)
801782
* @param int $value
802-
* @param bool $isError Error or Boolean?
783+
* @param int $isError Error or Boolean?
803784
* @param int $xfIndex
804785
*
805786
* @return int
@@ -1618,7 +1599,7 @@ private function writePanes(): void
16181599
return;
16191600
}
16201601

1621-
[$column, $row] = Coordinate::indexesFromString($this->phpSheet->getFreezePane() ?? '');
1602+
[$column, $row] = Coordinate::indexesFromString($this->phpSheet->getFreezePane());
16221603
$x = $column - 1;
16231604
$y = $row - 1;
16241605

@@ -1632,7 +1613,7 @@ private function writePanes(): void
16321613

16331614
// Determine which pane should be active. There is also the undocumented
16341615
// option to override this should it be necessary: may be removed later.
1635-
$pnnAct = null;
1616+
$pnnAct = 0;
16361617
if ($x != 0 && $y != 0) {
16371618
$pnnAct = 0; // Bottom right
16381619
}
@@ -2197,7 +2178,7 @@ public function insertBitmap($row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1,
21972178
$height *= $scale_y;
21982179

21992180
// Calculate the vertices of the image and write the OBJ record
2200-
$this->positionImage($col, $row, $x, $y, $width, $height);
2181+
$this->positionImage($col, $row, $x, $y, (int) $width, (int) $height);
22012182

22022183
// Write the IMDATA record to store the bitmap data
22032184
$record = 0x007f;
@@ -2442,7 +2423,7 @@ public function processBitmap($bitmap)
24422423
}
24432424

24442425
// Slurp the file into a string.
2445-
$data = fread($bmp_fd, filesize($bitmap));
2426+
$data = (string) fread($bmp_fd, (int) filesize($bitmap));
24462427

24472428
// Check that the file is big enough to be a bitmap.
24482429
if (strlen($data) <= 0x36) {
@@ -2451,9 +2432,8 @@ public function processBitmap($bitmap)
24512432

24522433
// The first 2 bytes are used to identify the bitmap.
24532434

2454-
/** @phpstan-ignore-next-line */
24552435
$identity = unpack('A2ident', $data);
2456-
if ($identity['ident'] != 'BM') {
2436+
if ($identity === false || $identity['ident'] != 'BM') {
24572437
throw new WriterException("$bitmap doesn't appear to be a valid bitmap image.\n");
24582438
}
24592439

@@ -2463,7 +2443,7 @@ public function processBitmap($bitmap)
24632443
// Read and remove the bitmap size. This is more reliable than reading
24642444
// the data size at offset 0x22.
24652445
//
2466-
$size_array = unpack('Vsa', substr($data, 0, 4));
2446+
$size_array = unpack('Vsa', substr($data, 0, 4)) ?: [];
24672447
$size = $size_array['sa'];
24682448
$data = substr($data, 4);
24692449
$size -= 0x36; // Subtract size of bitmap header.
@@ -2473,7 +2453,7 @@ public function processBitmap($bitmap)
24732453
$data = substr($data, 12);
24742454

24752455
// Read and remove the bitmap width and height. Verify the sizes.
2476-
$width_and_height = unpack('V2', substr($data, 0, 8));
2456+
$width_and_height = unpack('V2', substr($data, 0, 8)) ?: [];
24772457
$width = $width_and_height[1];
24782458
$height = $width_and_height[2];
24792459
$data = substr($data, 8);
@@ -2487,7 +2467,7 @@ public function processBitmap($bitmap)
24872467
// Read and remove the bitmap planes and bpp data. Verify them.
24882468
$planes_and_bitcount = unpack('v2', substr($data, 0, 4));
24892469
$data = substr($data, 4);
2490-
if ($planes_and_bitcount[2] != 24) { // Bitcount
2470+
if ($planes_and_bitcount === false || $planes_and_bitcount[2] != 24) { // Bitcount
24912471
throw new WriterException("$bitmap isn't a 24bit true color bitmap.\n");
24922472
}
24932473
if ($planes_and_bitcount[1] != 1) {
@@ -2498,7 +2478,7 @@ public function processBitmap($bitmap)
24982478
$compression = unpack('Vcomp', substr($data, 0, 4));
24992479
$data = substr($data, 4);
25002480

2501-
if ($compression['comp'] != 0) {
2481+
if ($compression === false || $compression['comp'] != 0) {
25022482
throw new WriterException("$bitmap: compression not supported in bitmap image.\n");
25032483
}
25042484

0 commit comments

Comments
 (0)