Skip to content

Commit 304e2b8

Browse files
author
MarkBaker
committed
Merge branch 'master' into 2.0-Development
# Conflicts: # phpstan-baseline.neon
2 parents 297817f + 070bc68 commit 304e2b8

File tree

13 files changed

+114
-23
lines changed

13 files changed

+114
-23
lines changed

phpstan-baseline.neon

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,19 @@ parameters:
296296
path: src/PhpSpreadsheet/Calculation/Engineering/ErfC.php
297297

298298
-
299-
message: "#^Parameter \\#1 \\$callback of function set_error_handler expects \\(callable\\(int, string, string, int, array\\)\\: bool\\)\\|null, array\\{'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Calculation\\\\\\\\Exception', 'errorHandlerCallback'\\} given\\.$#"
299+
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\:\\:ISPMT\\(\\) has no return type specified\\.$#"
300300
count: 1
301-
path: src/PhpSpreadsheet/Calculation/ExceptionHandler.php
301+
path: src/PhpSpreadsheet/Calculation/Financial.php
302+
303+
-
304+
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\:\\:ISPMT\\(\\) has parameter \\$args with no type specified\\.$#"
305+
count: 1
306+
path: src/PhpSpreadsheet/Calculation/Financial.php
307+
308+
-
309+
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Financial\\:\\:NPV\\(\\) has parameter \\$args with no type specified\\.$#"
310+
count: 1
311+
path: src/PhpSpreadsheet/Calculation/Financial.php
302312

303313
-
304314
message: "#^Parameter \\#1 \\$year of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:isLeapYear\\(\\) expects int\\|string, array\\|int\\|string given\\.$#"

phpstan-conditional.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
'path' => __DIR__ . '/src/PhpSpreadsheet/Shared/StringHelper.php',
4747
'count' => 1,
4848
];
49+
} else {
50+
// Flagged in Php8+ - unsure how to correct code
51+
$config['parameters']['ignoreErrors'][] = [
52+
'message' => '#^Binary operation "/" between float and array[|]float[|]int[|]string results in an error.#',
53+
'path' => __DIR__ . '/src/PhpSpreadsheet/Calculation/MathTrig/Combinations.php',
54+
'count' => 2,
55+
];
4956
}
5057

5158
return $config;

src/PhpSpreadsheet/Calculation/ArrayEnabled.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private static function initialiseHelper($arguments): void
2020
if (self::$arrayArgumentHelper === null) {
2121
self::$arrayArgumentHelper = new ArrayArgumentHelper();
2222
}
23-
self::$arrayArgumentHelper->initialise($arguments ?: []);
23+
self::$arrayArgumentHelper->initialise(($arguments === false) ? [] : $arguments);
2424
}
2525

2626
/**

src/PhpSpreadsheet/Calculation/ExceptionHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class ExceptionHandler
99
*/
1010
public function __construct()
1111
{
12-
set_error_handler([Exception::class, 'errorHandlerCallback'], E_ALL);
12+
/** @var callable */
13+
$callable = [Exception::class, 'errorHandlerCallback'];
14+
set_error_handler($callable, E_ALL);
1315
}
1416

1517
/**

src/PhpSpreadsheet/Helper/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ protected function parseTextNode(DOMText $textNode): void
795795
$domText = preg_replace(
796796
'/\s+/u',
797797
' ',
798-
str_replace(["\r", "\n"], ' ', $textNode->nodeValue ?: '')
798+
str_replace(["\r", "\n"], ' ', $textNode->nodeValue ?? '')
799799
);
800800
$this->stringData .= $domText;
801801
$this->buildTextRun();

src/PhpSpreadsheet/Reader/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ protected function processDomElement(DOMNode $element, Worksheet $sheet, int &$r
580580
{
581581
foreach ($element->childNodes as $child) {
582582
if ($child instanceof DOMText) {
583-
$domText = preg_replace('/\s+/u', ' ', trim($child->nodeValue ?: ''));
583+
$domText = preg_replace('/\s+/u', ' ', trim($child->nodeValue ?? ''));
584584
if (is_string($cellContent)) {
585585
// simply append the text if the cell content is a plain text string
586586
$cellContent .= $domText;

src/PhpSpreadsheet/Reader/Ods.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public function loadIntoExisting($filename, Spreadsheet $spreadsheet)
325325
}
326326
$spreadsheet->setActiveSheetIndex($worksheetID);
327327

328-
if ($worksheetName) {
328+
if ($worksheetName || is_numeric($worksheetName)) {
329329
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in
330330
// formula cells... during the load, all formulae should be correct, and we're simply
331331
// bringing the worksheet name in line with the formula, not the reverse
@@ -628,7 +628,7 @@ private function lookForActiveSheet(DOMElement $settings, Spreadsheet $spreadshe
628628
foreach ($settings->getElementsByTagNameNS($configNs, 'config-item') as $t) {
629629
if ($t->getAttributeNs($configNs, 'name') === 'ActiveTable') {
630630
try {
631-
$spreadsheet->setActiveSheetIndexByName($t->nodeValue ?: '');
631+
$spreadsheet->setActiveSheetIndexByName($t->nodeValue ?? '');
632632
} catch (Throwable $e) {
633633
// do nothing
634634
}

src/PhpSpreadsheet/Reader/Slk.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ private function processPRecord(array $rowData, Spreadsheet &$spreadsheet): void
411411

412412
break;
413413
case 'M':
414-
$formatArray['font']['size'] = substr($rowDatum, 1) / 20;
414+
$formatArray['font']['size'] = ((float) substr($rowDatum, 1)) / 20;
415415

416416
break;
417417
case 'L':

src/PhpSpreadsheet/Reader/Xls/MD5.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
class MD5
66
{
7-
// Context
8-
97
/**
108
* @var int
119
*/
@@ -26,11 +24,17 @@ class MD5
2624
*/
2725
private $d;
2826

27+
/**
28+
* @var int
29+
*/
30+
private static $allOneBits;
31+
2932
/**
3033
* MD5 stream constructor.
3134
*/
3235
public function __construct()
3336
{
37+
self::$allOneBits = self::signedInt(0xffffffff);
3438
$this->reset();
3539
}
3640

@@ -40,8 +44,8 @@ public function __construct()
4044
public function reset(): void
4145
{
4246
$this->a = 0x67452301;
43-
$this->b = 0xEFCDAB89;
44-
$this->c = 0x98BADCFE;
47+
$this->b = self::signedInt(0xEFCDAB89);
48+
$this->c = self::signedInt(0x98BADCFE);
4549
$this->d = 0x10325476;
4650
}
4751

@@ -156,10 +160,10 @@ public function add(string $data): void
156160
self::step($I, $C, $D, $A, $B, $words[2], 15, 0x2ad7d2bb);
157161
self::step($I, $B, $C, $D, $A, $words[9], 21, 0xeb86d391);
158162

159-
$this->a = ($this->a + $A) & 0xffffffff;
160-
$this->b = ($this->b + $B) & 0xffffffff;
161-
$this->c = ($this->c + $C) & 0xffffffff;
162-
$this->d = ($this->d + $D) & 0xffffffff;
163+
$this->a = ($this->a + $A) & self::$allOneBits;
164+
$this->b = ($this->b + $B) & self::$allOneBits;
165+
$this->c = ($this->c + $C) & self::$allOneBits;
166+
$this->d = ($this->d + $D) & self::$allOneBits;
163167
}
164168

165169
private static function f(int $X, int $Y, int $Z): int
@@ -182,18 +186,25 @@ private static function i(int $X, int $Y, int $Z): int
182186
return $Y ^ ($X | (~$Z)); // Y XOR (X OR NOT Z)
183187
}
184188

185-
private static function step(callable $func, int &$A, int $B, int $C, int $D, int $M, int $s, int $t): void
189+
/** @param float|int $t may be float on 32-bit system */
190+
private static function step(callable $func, int &$A, int $B, int $C, int $D, int $M, int $s, $t): void
186191
{
187-
$A = ($A + call_user_func($func, $B, $C, $D) + $M + $t) & 0xffffffff;
192+
$t = self::signedInt($t);
193+
$A = ($A + call_user_func($func, $B, $C, $D) + $M + $t) & self::$allOneBits;
188194
$A = self::rotate($A, $s);
189-
$A = ($B + $A) & 0xffffffff;
195+
$A = ($B + $A) & self::$allOneBits;
196+
}
197+
198+
/** @param float|int $result may be float on 32-bit system */
199+
private static function signedInt($result): int
200+
{
201+
return is_int($result) ? $result : (int) (PHP_INT_MIN + $result - 1 - PHP_INT_MAX);
190202
}
191203

192-
/** @return float|int */
193-
private static function rotate(int $decimal, int $bits)
204+
private static function rotate(int $decimal, int $bits): int
194205
{
195206
$binary = str_pad(decbin($decimal), 32, '0', STR_PAD_LEFT);
196207

197-
return bindec(substr($binary, $bits) . substr($binary, 0, $bits));
208+
return self::signedInt(bindec(substr($binary, $bits) . substr($binary, 0, $bits)));
198209
}
199210
}

tests/PhpSpreadsheetTests/Helper/HtmlTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function providerUtf8EncodingSupport(): array
2828
['können', 'können'],
2929
['русский', 'русский'],
3030
["foo\nbar", '<p>foo</p><p>bar</p>'],
31+
'issue2810' => ['0', '0'],
3132
];
3233
}
3334
}

0 commit comments

Comments
 (0)