Instance Variable for Array Return Type

Till now we have used a static variable/getter/setter to decide what type of result should be returned when a formula is evaluated and an array is the result. This is messy; it would be much better to use an instance variable instead. We cannot eliminate `setArrayReturnType` and `getArrayReturnType` because that would be a BC break. I am considering whether they should be deprecated. In the meantime, I have added a new instance property `instanceArrayReturnType` with getter and setter methods. The property is initially null, and, if it remains so when needed, the static property will be used instead. However, if it is set, its value will be used.
This commit is contained in:
oleibman
2024-07-10 09:19:51 -07:00
parent fda48554b2
commit b00dd47c28
24 changed files with 137 additions and 266 deletions
@@ -9,18 +9,6 @@ use PHPUnit\Framework\TestCase;
class ArrayFormulaTest extends TestCase
{
private string $arrayReturnType;
protected function setUp(): void
{
$this->arrayReturnType = Calculation::getArrayReturnType();
}
protected function tearDown(): void
{
Calculation::setArrayReturnType($this->arrayReturnType);
}
/**
* @dataProvider arrayFormulaReaderProvider
*/
@@ -43,7 +31,7 @@ class ArrayFormulaTest extends TestCase
self::assertEmpty($cell->getFormulaAttributes());
}
self::assertSame($expectedFormula, strtoupper($cell->getValue()));
Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);
Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);
$worksheet->calculateArrays();
$cell = $worksheet->getCell($cellAddress);
self::assertSame($expectedValue, $cell->getCalculatedValue());