Skip to content

Commit f84724d

Browse files
committed
Upgrade Phpstan
Too many problems with Dependabot update.
1 parent c00c2df commit f84724d

File tree

15 files changed

+37
-36
lines changed

15 files changed

+37
-36
lines changed

composer.lock

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

src/PhpSpreadsheet/Helper/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ public static function colourNameLookup(string $colorName): string
720720

721721
protected function startFontTag(DOMElement $tag): void
722722
{
723-
$attrs = $tag->attributes;
723+
$attrs = $tag->attributes ?? [];
724724
/** @var DOMAttr $attribute */
725725
foreach ($attrs as $attribute) {
726726
$attributeName = strtolower($attribute->name);

src/PhpSpreadsheet/IOFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ private static function getReaderTypeFromExtension(string $filename): ?string
227227
*/
228228
public static function registerWriter(string $writerType, string $writerClass): void
229229
{
230-
if (!is_a($writerClass, IWriter::class, true)) {
230+
// We want phpstan to validate caller, but still need this test
231+
if (!is_a($writerClass, IWriter::class, true)) { //* @phpstan-ignore-line
231232
throw new Writer\Exception('Registered writers must implement ' . IWriter::class);
232233
}
233234

@@ -241,7 +242,8 @@ public static function registerWriter(string $writerType, string $writerClass):
241242
*/
242243
public static function registerReader(string $readerType, string $readerClass): void
243244
{
244-
if (!is_a($readerClass, IReader::class, true)) {
245+
// We want phpstan to validate caller, but still need this test
246+
if (!is_a($readerClass, IReader::class, true)) { //* @phpstan-ignore-line
245247
throw new Reader\Exception('Registered readers must implement ' . IReader::class);
246248
}
247249

src/PhpSpreadsheet/Reader/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ private function processDomElementBody(Worksheet $sheet, int &$row, string &$col
338338
{
339339
$attributeArray = [];
340340
/** @var DOMAttr $attribute */
341-
foreach ($child->attributes as $attribute) {
341+
foreach (($child->attributes ?? []) as $attribute) {
342342
$attributeArray[$attribute->name] = $attribute->value;
343343
}
344344

src/PhpSpreadsheet/Settings.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public static function getLocale(): string
5757
*/
5858
public static function setChartRenderer(string $rendererClassName): void
5959
{
60-
if (!is_a($rendererClassName, IRenderer::class, true)) {
60+
// We want phpstan to validate caller, but still need this test
61+
if (!is_a($rendererClassName, IRenderer::class, true)) { //* @phpstan-ignore-line
6162
throw new Exception('Chart renderer must implement ' . IRenderer::class);
6263
}
6364

src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function stream_open(string $path, string $mode, int $options, ?string &$
6666
return false;
6767
}
6868
$this->ole = $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']]; //* @phpstan-ignore-line
69-
if (!($this->ole instanceof OLE)) {
69+
if (!($this->ole instanceof OLE)) { //* @phpstan-ignore-line
7070
throw new Exception('class is not OLE');
7171
}
7272

src/PhpSpreadsheet/Shared/StringHelper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ public static function sanitizeUTF8(string $textValue): string
317317
$textValue = str_replace(["\xef\xbf\xbe", "\xef\xbf\xbf"], "\xef\xbf\xbd", $textValue);
318318
$subst = mb_substitute_character(); // default is question mark
319319
mb_substitute_character(65533); // Unicode substitution character
320-
// Phpstan does not think this can return false.
321-
$returnValue = mb_convert_encoding($textValue, 'UTF-8', 'UTF-8');
320+
$returnValue = (string) mb_convert_encoding($textValue, 'UTF-8', 'UTF-8');
322321
mb_substitute_character($subst);
323322

324323
return $returnValue;
@@ -411,7 +410,7 @@ public static function convertEncoding(string $textValue, string $to, string $fr
411410
}
412411
}
413412

414-
return mb_convert_encoding($textValue, $to, $from);
413+
return (string) mb_convert_encoding($textValue, $to, $from);
415414
}
416415

417416
/**

src/PhpSpreadsheet/Style/NumberFormat/NumberFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public static function padValue(string $value, string $baseFormat): string
280280
$preDecimal = $postDecimal = '';
281281
$pregArray = preg_split('/\.(?=(?:[^"]*"[^"]*")*[^"]*\Z)/miu', $baseFormat . '.?');
282282
if (is_array($pregArray)) {
283-
$preDecimal = $pregArray[0] ?? '';
283+
$preDecimal = $pregArray[0];
284284
$postDecimal = $pregArray[1] ?? '';
285285
}
286286

src/PhpSpreadsheet/Writer/Csv.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ private function writeLine($fileHandle, array $values): void
325325

326326
// Write to file
327327
if ($this->outputEncoding != '') {
328-
$line = mb_convert_encoding($line, $this->outputEncoding);
328+
$line = (string) mb_convert_encoding($line, $this->outputEncoding);
329329
}
330330
fwrite($fileHandle, $line);
331331
}

tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
66

7+
use DateTimeInterface;
78
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
89
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Date;
910
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
@@ -119,9 +120,8 @@ public function testDATEtoDateTimeObject(): void
119120

120121
$result = Date::fromYMD(2012, 1, 31);
121122
// Must return an object...
122-
self::assertIsObject($result);
123123
// ... of the correct type
124-
self::assertTrue(is_a($result, 'DateTimeInterface'));
124+
self::assertInstanceOf(DateTimeInterface::class, $result);
125125
// ... with the correct value
126126
self::assertEquals($result->format('d-M-Y'), '31-Jan-2012');
127127
}

0 commit comments

Comments
 (0)