From b03544469bebe9111f36b442fd6b22146aaa5378 Mon Sep 17 00:00:00 2001 From: Owen Leibman Date: Wed, 30 Jun 2021 18:56:25 -0700 Subject: [PATCH] 2 Tests vs. Scrutinizer/Phpstan Just reviewing Scrutinizer's list of "bugs". There are 19 ascribed to me. For some, I will definitely take no action (e.g. use of bitwise operators in AND, OR, and XOR functions). However, where I can clean things up so that Scrutinizer is satisfied and the resulting code is not too contorted, I will make an attempt. This PR corrects 2 problems according to Scrutinizer, and 1 per Phpstan. Only test members are involved. --- phpstan-baseline.neon | 5 ----- .../Calculation/Functions/MathTrig/SubTotalTest.php | 2 +- .../Writer/Html/ImagesRootTest.php | 12 +++++++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 274764b1f..78979ae92 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6800,11 +6800,6 @@ parameters: count: 3 path: tests/PhpSpreadsheetTests/Writer/Html/HtmlCommentsTest.php - - - message: "#^Parameter \\#1 \\$directory of function chdir expects string, string\\|false given\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Writer/Html/ImagesRootTest.php - - message: "#^Parameter \\#1 \\$options of static method PhpOffice\\\\PhpSpreadsheet\\\\Settings\\:\\:setLibXmlLoaderOptions\\(\\) expects int, null given\\.$#" count: 1 diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php index 2a54e4591..cf79ac0b1 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php @@ -92,7 +92,7 @@ class SubTotalTest extends AllSetupTeardown '12' => false, ]; foreach ($visibleRows as $row => $visible) { - $rowDimension = $sheet->getRowDimension($row); + $rowDimension = $sheet->getRowDimension((int) $row); $rowDimension->setVisible($visible); } $sheet->getCell('D2')->setValue("=SUBTOTAL($type, A1:$maxCol$maxRow)"); diff --git a/tests/PhpSpreadsheetTests/Writer/Html/ImagesRootTest.php b/tests/PhpSpreadsheetTests/Writer/Html/ImagesRootTest.php index 40099177f..b36a87c0b 100644 --- a/tests/PhpSpreadsheetTests/Writer/Html/ImagesRootTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Html/ImagesRootTest.php @@ -10,13 +10,18 @@ use PhpOffice\PhpSpreadsheetTests\Functional; class ImagesRootTest extends Functional\AbstractFunctional { /** - * @var false|string + * @var string */ - private $curdir; + private $curdir = ''; protected function setUp(): void { - $this->curdir = getcwd(); + $curdir = getcwd(); + if ($curdir === false) { + self::fail('Unable to obtain current directory'); + } else { + $this->curdir = $curdir; + } } protected function tearDown(): void @@ -64,5 +69,6 @@ class ImagesRootTest extends Functional\AbstractFunctional self::assertCount(1, $img); self::assertEquals("$root/$stub", $img[0]->getAttribute('src')); self::assertEquals($desc, $img[0]->getAttribute('alt')); + $spreadsheet->disconnectWorksheets(); } }