Skip to content

Commit a61f9f1

Browse files
authored
Merge pull request #4701 from oleibman/phpstan2131
Upgrade Phpstan
2 parents 4db18ea + 93c5f0d commit a61f9f1

File tree

8 files changed

+36
-35
lines changed

8 files changed

+36
-35
lines changed

composer.lock

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,6 +2581,8 @@ public function extractCellRange(string &$range = 'A1', ?Worksheet $worksheet =
25812581
if (!isset($aReferences[1])) {
25822582
// Single cell in range
25832583
sscanf($aReferences[0], '%[A-Z]%d', $currentCol, $currentRow);
2584+
/** @var string $currentCol */
2585+
/** @var int $currentRow */
25842586
if ($createCell && $worksheet !== null && !$worksheet->cellExists($aReferences[0])) {
25852587
$worksheet->setCellValue($aReferences[0], null);
25862588
}
@@ -2600,6 +2602,8 @@ public function extractCellRange(string &$range = 'A1', ?Worksheet $worksheet =
26002602
foreach ($aReferences as $reference) {
26012603
// Extract range
26022604
sscanf($reference, '%[A-Z]%d', $currentCol, $currentRow);
2605+
/** @var string $currentCol */
2606+
/** @var int $currentRow */
26032607
if ($createCell && $worksheet !== null && !$worksheet->cellExists($reference)) {
26042608
$worksheet->setCellValue($reference, null);
26052609
}

src/PhpSpreadsheet/Calculation/LookupRef/Lookup.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public static function lookup(mixed $lookupValue, mixed $lookupVector, $resultVe
4747
$lookupVector = array_shift($lookupVector);
4848
}
4949

50-
/** @var mixed[] $lookupVector */
51-
/** @var mixed[] $resultVector */
50+
/** @var array<int, mixed> $lookupVector */
51+
/** @var array<int, mixed> $resultVector */
5252
if ($lookupColumns !== 2) {
5353
$lookupVector = self::verifyLookupValues($lookupVector, $resultVector);
5454
}
@@ -57,8 +57,8 @@ public static function lookup(mixed $lookupValue, mixed $lookupVector, $resultVe
5757
}
5858

5959
/**
60-
* @param mixed[] $lookupVector
61-
* @param mixed[] $resultVector
60+
* @param array<int, mixed> $lookupVector
61+
* @param array<int, mixed> $resultVector
6262
*
6363
* @return mixed[]
6464
*/
@@ -80,6 +80,7 @@ private static function verifyLookupValues(array $lookupVector, array $resultVec
8080
if (is_array($dataValue2)) {
8181
$dataValue2 = array_shift($dataValue2);
8282
}
83+
/** @var int $key2 */
8384
$value = [$key1 => $dataValue1, $key2 => $dataValue2];
8485
}
8586
unset($value);

src/PhpSpreadsheet/Calculation/LookupRef/Matrix.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static function index(mixed $matrix, mixed $rowNum = 0, mixed $columnNum
150150

151151
/**
152152
* @param mixed[] $matrix
153-
* @param mixed[] $rowKeys
153+
* @param array<int, int> $rowKeys
154154
*/
155155
private static function extractRowValue(array $matrix, array $rowKeys, int $rowNum): mixed
156156
{
@@ -159,7 +159,7 @@ private static function extractRowValue(array $matrix, array $rowKeys, int $rowN
159159
}
160160

161161
$rowNum = $rowKeys[--$rowNum];
162-
$row = $matrix[$rowNum]; //* @phpstan-ignore-line
162+
$row = $matrix[$rowNum];
163163
if (is_array($row)) {
164164
return [$rowNum => $row];
165165
}

src/PhpSpreadsheet/Calculation/LookupRef/Selection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function choose(mixed $chosenEntry, mixed ...$chooseArgs): mixed
3737
} else {
3838
return ExcelError::VALUE();
3939
}
40-
$chosenEntry = floor($chosenEntry);
40+
$chosenEntry = (int) floor($chosenEntry);
4141
if (($chosenEntry < 0) || ($chosenEntry > $entryCount)) {
4242
return ExcelError::VALUE();
4343
}

src/PhpSpreadsheet/Shared/Drawing.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ public static function pixelsToCellDimension(int $pixelValue, \PhpOffice\PhpSpre
4949
// Font name and size
5050
$name = $defaultFont->getName();
5151
$size = $defaultFont->getSize();
52+
$sizex = ($size !== null && $size == (int) $size) ? ((int) $size) : "$size";
5253

53-
if (isset(Font::DEFAULT_COLUMN_WIDTHS[$name][$size])) {
54+
if (isset(Font::DEFAULT_COLUMN_WIDTHS[$name][$sizex])) {
5455
// Exact width can be determined
55-
return $pixelValue * Font::DEFAULT_COLUMN_WIDTHS[$name][$size]['width']
56-
/ Font::DEFAULT_COLUMN_WIDTHS[$name][$size]['px'];
56+
return $pixelValue * Font::DEFAULT_COLUMN_WIDTHS[$name][$sizex]['width']
57+
/ Font::DEFAULT_COLUMN_WIDTHS[$name][$sizex]['px'];
5758
}
5859

5960
// We don't have data for this particular font and size, use approximation by
@@ -75,11 +76,12 @@ public static function cellDimensionToPixels(float $cellWidth, \PhpOffice\PhpSpr
7576
// Font name and size
7677
$name = $defaultFont->getName();
7778
$size = $defaultFont->getSize();
79+
$sizex = ($size !== null && $size == (int) $size) ? ((int) $size) : "$size";
7880

79-
if (isset(Font::DEFAULT_COLUMN_WIDTHS[$name][$size])) {
81+
if (isset(Font::DEFAULT_COLUMN_WIDTHS[$name][$sizex])) {
8082
// Exact width can be determined
81-
$colWidth = $cellWidth * Font::DEFAULT_COLUMN_WIDTHS[$name][$size]['px']
82-
/ Font::DEFAULT_COLUMN_WIDTHS[$name][$size]['width'];
83+
$colWidth = $cellWidth * Font::DEFAULT_COLUMN_WIDTHS[$name][$sizex]['px']
84+
/ Font::DEFAULT_COLUMN_WIDTHS[$name][$sizex]['width'];
8385
} else {
8486
// We don't have data for this particular font and size, use approximation by
8587
// extrapolating from Calibri 11
@@ -114,11 +116,7 @@ public static function pixelsToPoints(int $pixelValue): float
114116
*/
115117
public static function pointsToPixels($pointValue): int
116118
{
117-
if ($pointValue != 0) {
118-
return (int) ceil($pointValue / 0.75);
119-
}
120-
121-
return 0;
119+
return (int) ceil($pointValue / 0.75);
122120
}
123121

124122
/**

src/PhpSpreadsheet/Shared/Font.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,13 @@ public static function getCharsetFromFontName(string $fontName): int
631631
*/
632632
public static function getDefaultColumnWidthByFont(FontStyle $font, bool $returnAsPixels = false): float|int
633633
{
634-
if (isset(self::DEFAULT_COLUMN_WIDTHS[$font->getName()][$font->getSize()])) {
634+
$size = $font->getSize();
635+
$sizex = ($size !== null && $size == (int) $size) ? ((int) $size) : "$size";
636+
if (isset(self::DEFAULT_COLUMN_WIDTHS[$font->getName()][$sizex])) {
635637
// Exact width can be determined
636638
$columnWidth = $returnAsPixels
637-
? self::DEFAULT_COLUMN_WIDTHS[$font->getName()][$font->getSize()]['px']
638-
: self::DEFAULT_COLUMN_WIDTHS[$font->getName()][$font->getSize()]['width'];
639+
? self::DEFAULT_COLUMN_WIDTHS[$font->getName()][$sizex]['px']
640+
: self::DEFAULT_COLUMN_WIDTHS[$font->getName()][$sizex]['width'];
639641
} else {
640642
// We don't have data for this particular font and size, use approximation by
641643
// extrapolating from Calibri 11
@@ -665,8 +667,9 @@ public static function getDefaultRowHeightByFont(FontStyle $font): float
665667
{
666668
$name = $font->getName();
667669
$size = $font->getSize();
668-
if (isset(self::DEFAULT_COLUMN_WIDTHS[$name][$size])) {
669-
$rowHeight = self::DEFAULT_COLUMN_WIDTHS[$name][$size]['height'];
670+
$sizex = ($size !== null && $size == (int) $size) ? ((int) $size) : "$size";
671+
if (isset(self::DEFAULT_COLUMN_WIDTHS[$name][$sizex])) {
672+
$rowHeight = self::DEFAULT_COLUMN_WIDTHS[$name][$sizex]['height'];
670673
} elseif ($name === 'Arial' || $name === 'Verdana') {
671674
$rowHeight = self::DEFAULT_COLUMN_WIDTHS[$name][10]['height'] * $size / 10.0;
672675
} else {

tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImCscTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public function testImCscArray(array $expectedResult, string $complex): void
9898
$string = preg_replace('/(\d{8})\d+/', '$1', $string);
9999
}
100100
}
101-
foreach ($result as &$array) {
102-
foreach ($array as &$string) {
103-
$string = preg_replace('/(\d{8})\d+/', '$1', $string);
101+
foreach ($result as &$array2) {
102+
foreach ($array2 as &$string2) {
103+
$string2 = preg_replace('/(\d{8})\d+/', '$1', $string2);
104104
}
105105
}
106106

0 commit comments

Comments
 (0)