Skip to content

Commit 68158c8

Browse files
authored
Phpstan Differences from Php7 to Php8, Again (#2665)
These changes have already been implemented twice, and been regressed twice. I'll try once more (with a different approach), then give up ... As configured, Phpstan running under Php7 reports no errors. However, running under Php8, it reports 100 (!) errors. The vast majority of these are due to two reasons: - renaming parameters in Php builtin functions in preparation for named parameters. - using the new class GdImage rather than type resource as the argument type for many image-based functions. Regardless of the cause, this will be a problem sooner or later. This PR is an attempt to get ahead of that problem. For source members, it mostly adds annotations or updates doc-blocks. Only 2 members have changes to executable code, and these are very minor - BitWise and Writer/Xlsx. For test members, all baseline errors are deleted and the code is fixed. Php7 and Php8 both report no errors with this configuration.
1 parent c0ea894 commit 68158c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+199
-544
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 460 deletions
Large diffs are not rendered by default.

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,6 +3226,7 @@ public function _translateFormulaToEnglish($formula)
32263226
if (self::$functionReplaceToExcel === null) {
32273227
self::$functionReplaceToExcel = [];
32283228
foreach (array_keys(self::$localeFunctions) as $excelFunctionName) {
3229+
// @phpstan-ignore-next-line
32293230
self::$functionReplaceToExcel[] = '$1' . trim($excelFunctionName) . '$2';
32303231
}
32313232
foreach (array_keys(self::$localeBoolean) as $excelBoolean) {
@@ -4490,6 +4491,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $cell = null)
44904491
if ($operand1Data['reference'] === null) {
44914492
if ((trim($operand1Data['value']) != '') && (is_numeric($operand1Data['value']))) {
44924493
$operand1Data['reference'] = $cell->getColumn() . $operand1Data['value'];
4494+
// @phpstan-ignore-next-line
44934495
} elseif (trim($operand1Data['reference']) == '') {
44944496
$operand1Data['reference'] = $cell->getCoordinate();
44954497
} else {
@@ -4499,6 +4501,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $cell = null)
44994501
if ($operand2Data['reference'] === null) {
45004502
if ((trim($operand2Data['value']) != '') && (is_numeric($operand2Data['value']))) {
45014503
$operand2Data['reference'] = $cell->getColumn() . $operand2Data['value'];
4504+
// @phpstan-ignore-next-line
45024505
} elseif (trim($operand2Data['reference']) == '') {
45034506
$operand2Data['reference'] = $cell->getCoordinate();
45044507
} else {

src/PhpSpreadsheet/Calculation/Engineering/BitWise.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,14 @@ public static function BITRSHIFT($number, $shiftAmount)
211211
*
212212
* @param mixed $value
213213
*
214-
* @return float|int
214+
* @return float
215215
*/
216216
private static function validateBitwiseArgument($value)
217217
{
218218
$value = self::nullFalseTrueToNumber($value);
219219

220220
if (is_numeric($value)) {
221+
$value = (float) $value;
221222
if ($value == floor($value)) {
222223
if (($value > 2 ** 48 - 1) || ($value < 0)) {
223224
throw new Exception(ExcelError::NAN());

src/PhpSpreadsheet/Calculation/LookupRef/RowColumnInformation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public static function ROW($cellAddress = null, ?Cell $cell = null)
166166
function ($value) {
167167
return [$value];
168168
},
169+
// @phpstan-ignore-next-line
169170
range($startAddress, $endAddress)
170171
);
171172
}

src/PhpSpreadsheet/Cell/Coordinate.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public static function splitRange($range)
148148
$exploded = explode(',', $range);
149149
$counter = count($exploded);
150150
for ($i = 0; $i < $counter; ++$i) {
151+
// @phpstan-ignore-next-line
151152
$exploded[$i] = explode(':', $exploded[$i]);
152153
}
153154

@@ -544,7 +545,7 @@ private static function getCellBlocksFromRangeString($rangeString)
544545

545546
// split range sets on intersection (space) or union (,) operators
546547
$tokens = preg_split('/([ ,])/', $rangeString, -1, PREG_SPLIT_DELIM_CAPTURE);
547-
// separate the range sets and the operators into arrays
548+
/** @phpstan-ignore-next-line */
548549
$split = array_chunk($tokens, 2);
549550
$ranges = array_column($split, 0);
550551
$operators = array_column($split, 1);

src/PhpSpreadsheet/Helper/Html.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ protected function handleCallback(DOMElement $element, $callbackTag, array $call
808808
if (isset($callbacks[$callbackTag])) {
809809
$elementHandler = $callbacks[$callbackTag];
810810
if (method_exists($this, $elementHandler)) {
811+
// @phpstan-ignore-next-line
811812
call_user_func([$this, $elementHandler], $element);
812813
}
813814
}

src/PhpSpreadsheet/Reader/Xls/MD5.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function getContext()
7171
*/
7272
public function add(string $data): void
7373
{
74+
/** @phpstan-ignore-next-line */
7475
$words = array_values(unpack('V16', $data));
7576

7677
$A = $this->a;

src/PhpSpreadsheet/Shared/Drawing.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,15 @@ public static function imagecreatefrombmp($bmpFilename)
164164
{
165165
// Load the image into a string
166166
$file = fopen($bmpFilename, 'rb');
167+
/** @phpstan-ignore-next-line */
167168
$read = fread($file, 10);
169+
// @phpstan-ignore-next-line
168170
while (!feof($file) && ($read != '')) {
171+
// @phpstan-ignore-next-line
169172
$read .= fread($file, 1024);
170173
}
171174

175+
/** @phpstan-ignore-next-line */
172176
$temp = unpack('H*', $read);
173177
$hex = $temp[1];
174178
$header = substr($hex, 0, 108);
@@ -196,6 +200,8 @@ public static function imagecreatefrombmp($bmpFilename)
196200
$y = 1;
197201

198202
// Create newimage
203+
204+
/** @phpstan-ignore-next-line */
199205
$image = imagecreatetruecolor($width, $height);
200206

201207
// Grab the body from the image
@@ -241,7 +247,10 @@ public static function imagecreatefrombmp($bmpFilename)
241247
$b = hexdec($body[$i_pos] . $body[$i_pos + 1]);
242248

243249
// Calculate and draw the pixel
250+
251+
/** @phpstan-ignore-next-line */
244252
$color = imagecolorallocate($image, $r, $g, $b);
253+
// @phpstan-ignore-next-line
245254
imagesetpixel($image, $x, $height - $y, $color);
246255

247256
// Raise the horizontal position
@@ -252,6 +261,7 @@ public static function imagecreatefrombmp($bmpFilename)
252261
unset($body);
253262

254263
// Return image-object
264+
// @phpstan-ignore-next-line
255265
return $image;
256266
}
257267
}

src/PhpSpreadsheet/Shared/JAMA/Matrix.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ public function concat(...$args)
11341134
$this->checkMatrixDimensions($M);
11351135
for ($i = 0; $i < $this->m; ++$i) {
11361136
for ($j = 0; $j < $this->n; ++$j) {
1137+
// @phpstan-ignore-next-line
11371138
$this->A[$i][$j] = trim($this->A[$i][$j], '"') . trim($M->get($i, $j), '"');
11381139
}
11391140
}

src/PhpSpreadsheet/Shared/OLE.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ public function getStream($blockIdOrPps)
251251
*/
252252
private static function readInt1($fileHandle)
253253
{
254+
// @phpstan-ignore-next-line
254255
[, $tmp] = unpack('c', fread($fileHandle, 1));
255256

256257
return $tmp;
@@ -265,6 +266,7 @@ private static function readInt1($fileHandle)
265266
*/
266267
private static function readInt2($fileHandle)
267268
{
269+
// @phpstan-ignore-next-line
268270
[, $tmp] = unpack('v', fread($fileHandle, 2));
269271

270272
return $tmp;
@@ -279,6 +281,7 @@ private static function readInt2($fileHandle)
279281
*/
280282
private static function readInt4($fileHandle)
281283
{
284+
// @phpstan-ignore-next-line
282285
[, $tmp] = unpack('V', fread($fileHandle, 4));
283286

284287
return $tmp;

0 commit comments

Comments
 (0)