Skip to content

Commit c112802

Browse files
authored
Eliminate Most Scrutinizer Problems in Test Suite (#2699)
* Eliminate Most Scrutinizer Problems in Test Suite Mostly minor code changes, with some annotations. * Missed 2 php-cs-fixer Problems They should be fixed now.
1 parent 2482203 commit c112802

27 files changed

+184
-147
lines changed

tests/PhpSpreadsheetTests/Calculation/CalculationFunctionListTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function tearDown(): void
4141
* @param array|string $functionCall
4242
* @param string $argumentCount
4343
*/
44-
public function testGetFunctions($category, $functionCall, $argumentCount): void
44+
public function testGetFunctions(/** @scrutinizer ignore-unused */ $category, $functionCall, /** @scrutinizer ignore-unused */ $argumentCount): void
4545
{
4646
self::assertIsCallable($functionCall);
4747
}

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@
44

55
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
66
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
7-
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
87
use PHPUnit\Framework\TestCase;
98

109
class ComplexTest extends TestCase
1110
{
12-
protected function setUp(): void
13-
{
14-
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
15-
}
16-
1711
/**
1812
* @dataProvider providerCOMPLEX
1913
*
2014
* @param mixed $expectedResult
2115
*/
2216
public function testCOMPLEX($expectedResult, ...$args): void
2317
{
24-
$result = Engineering::COMPLEX(...$args);
18+
if (count($args) === 0) {
19+
$result = Engineering::COMPLEX();
20+
} elseif (count($args) === 1) {
21+
$result = Engineering::COMPLEX($args[0]);
22+
} elseif (count($args) === 2) {
23+
$result = Engineering::COMPLEX($args[0], $args[1]);
24+
} else {
25+
$result = Engineering::COMPLEX($args[0], $args[1], $args[2]);
26+
}
2527
self::assertEquals($expectedResult, $result);
2628
}
2729

tests/PhpSpreadsheetTests/Calculation/Functions/Financial/DollarDeTest.php

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

55
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
66
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
7-
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
87
use PHPUnit\Framework\TestCase;
98

109
class DollarDeTest extends TestCase
1110
{
12-
protected function setUp(): void
13-
{
14-
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
15-
}
16-
1711
/**
1812
* @dataProvider providerDOLLARDE
1913
*
2014
* @param mixed $expectedResult
2115
*/
2216
public function testDOLLARDE($expectedResult, ...$args): void
2317
{
24-
$result = Financial::DOLLARDE(...$args);
18+
if (count($args) === 0) {
19+
$result = Financial::DOLLARDE();
20+
} elseif (count($args) === 1) {
21+
$result = Financial::DOLLARDE($args[0]);
22+
} else {
23+
$result = Financial::DOLLARDE($args[0], $args[1]);
24+
}
2525
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
2626
}
2727

tests/PhpSpreadsheetTests/Calculation/Functions/Financial/DollarFrTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
44

55
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
6-
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
76
use PHPUnit\Framework\TestCase;
87

98
class DollarFrTest extends TestCase
109
{
11-
protected function setUp(): void
12-
{
13-
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
14-
}
15-
1610
/**
1711
* @dataProvider providerDOLLARFR
1812
*
1913
* @param mixed $expectedResult
2014
*/
2115
public function testDOLLARFR($expectedResult, ...$args): void
2216
{
23-
$result = Financial::DOLLARFR(...$args);
17+
if (count($args) === 0) {
18+
$result = Financial::DOLLARFR();
19+
} elseif (count($args) === 1) {
20+
$result = Financial::DOLLARFR($args[0]);
21+
} else {
22+
$result = Financial::DOLLARFR($args[0], $args[1]);
23+
}
2424
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
2525
}
2626

tests/PhpSpreadsheetTests/Calculation/Functions/Financial/FvTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,30 @@
33
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
44

55
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
6-
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
76
use PHPUnit\Framework\TestCase;
87

98
class FvTest extends TestCase
109
{
11-
protected function setUp(): void
12-
{
13-
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
14-
}
15-
1610
/**
1711
* @dataProvider providerFV
1812
*
1913
* @param mixed $expectedResult
2014
*/
2115
public function testFV($expectedResult, array $args): void
2216
{
23-
$result = Financial::FV(...$args);
17+
if (count($args) === 0) {
18+
$result = Financial::FV();
19+
} elseif (count($args) === 1) {
20+
$result = Financial::FV($args[0]);
21+
} elseif (count($args) === 2) {
22+
$result = Financial::FV($args[0], $args[1]);
23+
} elseif (count($args) === 3) {
24+
$result = Financial::FV($args[0], $args[1], $args[2]);
25+
} elseif (count($args) === 4) {
26+
$result = Financial::FV($args[0], $args[1], $args[2], $args[3]);
27+
} else {
28+
$result = Financial::FV($args[0], $args[1], $args[2], $args[3], $args[4]);
29+
}
2430
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
2531
}
2632

tests/PhpSpreadsheetTests/Calculation/Functions/Financial/NPerTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,30 @@
33
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
44

55
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
6-
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
76
use PHPUnit\Framework\TestCase;
87

98
class NPerTest extends TestCase
109
{
11-
protected function setUp(): void
12-
{
13-
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
14-
}
15-
1610
/**
1711
* @dataProvider providerNPER
1812
*
1913
* @param mixed $expectedResult
2014
*/
2115
public function testNPER($expectedResult, array $args): void
2216
{
23-
$result = Financial::NPER(...$args);
17+
if (count($args) === 0) {
18+
$result = Financial::NPER();
19+
} elseif (count($args) === 1) {
20+
$result = Financial::NPER($args[0]);
21+
} elseif (count($args) === 2) {
22+
$result = Financial::NPER($args[0], $args[1]);
23+
} elseif (count($args) === 3) {
24+
$result = Financial::NPER($args[0], $args[1], $args[2]);
25+
} elseif (count($args) === 4) {
26+
$result = Financial::NPER($args[0], $args[1], $args[2], $args[3]);
27+
} else {
28+
$result = Financial::NPER($args[0], $args[1], $args[2], $args[3], $args[4]);
29+
}
2430
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
2531
}
2632

tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PDurationTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
44

55
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
6-
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
76
use PHPUnit\Framework\TestCase;
87

98
class PDurationTest extends TestCase
109
{
11-
protected function setUp(): void
12-
{
13-
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
14-
}
15-
1610
/**
1711
* @dataProvider providerPDURATION
1812
*
1913
* @param mixed $expectedResult
2014
*/
2115
public function testPDURATION($expectedResult, array $args): void
2216
{
23-
$result = Financial::PDURATION(...$args);
17+
if (count($args) === 0) {
18+
$result = Financial::PDURATION();
19+
} elseif (count($args) === 1) {
20+
$result = Financial::PDURATION($args[0]);
21+
} elseif (count($args) === 2) {
22+
$result = Financial::PDURATION($args[0], $args[1]);
23+
} else {
24+
$result = Financial::PDURATION($args[0], $args[1], $args[2]);
25+
}
2426
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
2527
}
2628

tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PmtTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
44

55
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
6-
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
76
use PHPUnit\Framework\TestCase;
87

98
class PmtTest extends TestCase
109
{
11-
protected function setUp(): void
12-
{
13-
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
14-
}
15-
1610
/**
1711
* @dataProvider providerPMT
1812
*
@@ -23,7 +17,13 @@ public function testPMT($expectedResult, array $args): void
2317
$interestRate = array_shift($args);
2418
$numberOfPeriods = array_shift($args);
2519
$presentValue = array_shift($args);
26-
$result = Financial::PMT($interestRate, $numberOfPeriods, $presentValue, ...$args);
20+
if (count($args) === 0) {
21+
$result = Financial::PMT($interestRate, $numberOfPeriods, $presentValue);
22+
} elseif (count($args) === 1) {
23+
$result = Financial::PMT($interestRate, $numberOfPeriods, $presentValue, $args[0]);
24+
} else {
25+
$result = Financial::PMT($interestRate, $numberOfPeriods, $presentValue, $args[0], $args[1]);
26+
}
2727
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
2828
}
2929

tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PvTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,30 @@
33
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
44

55
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
6-
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
76
use PHPUnit\Framework\TestCase;
87

98
class PvTest extends TestCase
109
{
11-
protected function setUp(): void
12-
{
13-
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
14-
}
15-
1610
/**
1711
* @dataProvider providerPV
1812
*
1913
* @param mixed $expectedResult
2014
*/
2115
public function testPV($expectedResult, array $args): void
2216
{
23-
$result = Financial::PV(...$args);
17+
if (count($args) === 0) {
18+
$result = Financial::PV();
19+
} elseif (count($args) === 1) {
20+
$result = Financial::PV($args[0]);
21+
} elseif (count($args) === 2) {
22+
$result = Financial::PV($args[0], $args[1]);
23+
} elseif (count($args) === 3) {
24+
$result = Financial::PV($args[0], $args[1], $args[2]);
25+
} elseif (count($args) === 4) {
26+
$result = Financial::PV($args[0], $args[1], $args[2], $args[3]);
27+
} else {
28+
$result = Financial::PV($args[0], $args[1], $args[2], $args[3], $args[4]);
29+
}
2430
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
2531
}
2632

tests/PhpSpreadsheetTests/Calculation/Functions/Financial/RriTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
44

55
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
6-
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
76
use PHPUnit\Framework\TestCase;
87

98
class RriTest extends TestCase
109
{
11-
protected function setUp(): void
12-
{
13-
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
14-
}
15-
1610
/**
1711
* @dataProvider providerRRI
1812
*
1913
* @param mixed $expectedResult
2014
*/
2115
public function testRRI($expectedResult, array $args): void
2216
{
23-
$result = Financial::RRI(...$args);
17+
if (count($args) === 0) {
18+
$result = Financial::RRI();
19+
} elseif (count($args) === 1) {
20+
$result = Financial::RRI($args[0]);
21+
} elseif (count($args) === 2) {
22+
$result = Financial::RRI($args[0], $args[1]);
23+
} else {
24+
$result = Financial::RRI($args[0], $args[1], $args[2]);
25+
}
2426
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
2527
}
2628

0 commit comments

Comments
 (0)