Skip to content

Commit d516d9f

Browse files
author
MarkBaker
committed
Enable array-readiness for more Math/Trig functions
1 parent b300e18 commit d516d9f

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
99

1010
### Added
1111

12-
- Improved support for passing of array arguments to Excel function implementations to return array results (where appropriate). [PR #2562](https://github.com/PHPOffice/PhpSpreadsheet/pull/2562)
12+
- Improved support for passing of array arguments to Excel function implementations to return array results (where appropriate). [Issue #2551](https://github.com/PHPOffice/PhpSpreadsheet/issues/2551)
1313

1414
This is the first stage in an ongoing process of adding array support to all appropriate function implementations,
1515
- Support for the Excel365 Math/Trig SEQUENCE() function [PR #2536](https://github.com/PHPOffice/PhpSpreadsheet/pull/2536)

src/PhpSpreadsheet/Calculation/MathTrig.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ public static function RAND($min = 0, $max = 0)
617617
* @param mixed $aValue Number to convert
618618
* @param mixed $style Number indicating one of five possible forms
619619
*
620-
* @return string Roman numeral, or a string containing an error
620+
* @return array|string Roman numeral, or a string containing an error
621621
*/
622622
public static function ROMAN($aValue, $style = 0)
623623
{

src/PhpSpreadsheet/Calculation/MathTrig/Roman.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
44

5+
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
56
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
67
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
78

89
class Roman
910
{
11+
use ArrayEnabled;
12+
1013
private const VALUES = [
1114
45 => ['VL'],
1215
46 => ['VLI'],
@@ -814,12 +817,20 @@ public static function calculateRoman(int $aValue, int $style): string
814817
* Converts a number to Roman numeral
815818
*
816819
* @param mixed $aValue Number to convert
820+
* Or can be an array of numbers
817821
* @param mixed $style Number indicating one of five possible forms
822+
* Or can be an array of styles
818823
*
819-
* @return string Roman numeral, or a string containing an error
824+
* @return array|string Roman numeral, or a string containing an error
825+
* If an array of numbers is passed as an argument, then the returned result will also be an array
826+
* with the same dimensions
820827
*/
821828
public static function evaluate($aValue, $style = 0)
822829
{
830+
if (is_array($aValue) || is_array($style)) {
831+
return self::evaluateArrayArguments([self::class, __FUNCTION__], $aValue, $style);
832+
}
833+
823834
try {
824835
$aValue = Helpers::validateNumericNullBool($aValue);
825836
if (is_bool($style)) {

tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RomanTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
44

5+
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
6+
57
class RomanTest extends AllSetupTeardown
68
{
79
/**
@@ -24,4 +26,25 @@ public function providerROMAN(): array
2426
{
2527
return require 'tests/data/Calculation/MathTrig/ROMAN.php';
2628
}
29+
30+
/**
31+
* @dataProvider providerRomanArray
32+
*/
33+
public function testRomanArray(array $expectedResult, string $values, string $styles): void
34+
{
35+
$calculation = Calculation::getInstance();
36+
37+
$formula = "=ROMAN({$values}, {$styles})";
38+
$result = $calculation->_calculateFormulaValue($formula);
39+
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
40+
}
41+
42+
public function providerRomanArray(): array
43+
{
44+
return [
45+
'row vector' => [[['XLIX', 'MMXXII', 'CDXCIX']], '{49, 2022, 499}', '0'],
46+
'column vector' => [[['XLIX'], ['MMXXII'], ['CDXCIX']], '{49; 2022; 499}', '0'],
47+
'matrix' => [[['XLIX', 'MMXXII'], ['LXIV', 'CDXCIX']], '{49, 2022; 64, 499}', '0'],
48+
];
49+
}
2750
}

0 commit comments

Comments
 (0)