Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid a PHP8.4 Deprecation #3789

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5072,7 +5072,7 @@ private function processTokenStack(mixed $tokens, $cellID = null, ?Cell $cell =
krsort($args);
krsort($emptyArguments);

if ($argCount > 0) {
if ($argCount > 0 && is_array($functionCall)) {
$args = $this->addDefaultArgumentValues($functionCall, $args, $emptyArguments);
}

Expand Down Expand Up @@ -5571,7 +5571,7 @@ public function getImplementedFunctionNames(): array

private function addDefaultArgumentValues(array $functionCall, array $args, array $emptyArguments): array
{
$reflector = new ReflectionMethod(implode('::', $functionCall));
$reflector = new ReflectionMethod($functionCall[0], $functionCall[1]);
$methodArguments = $reflector->getParameters();

if (count($methodArguments) > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;

class PiTest extends AllSetupTeardown
{
/**
* @dataProvider providerPI
*/
public function testPI(mixed $expectedResult, mixed $number = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($number !== null) {
$sheet->getCell('A1')->setValue($number);
}
if ($number === 'omitted') {
$sheet->getCell('B1')->setValue('=PI()');
} else {
$sheet->getCell('B1')->setValue('=PI(A1)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}

public static function providerPI(): array
{
return require 'tests/data/Calculation/MathTrig/PI.php';
}
}
8 changes: 8 additions & 0 deletions tests/data/Calculation/MathTrig/PI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

return [
[3.141592653589793],
'should not supply any arguments' => ['exception', 1],
];