Skip to content

Commit fdd9f8c

Browse files
committed
Better Definitions for Mixed Parameters and Values Part 4 of Many
Continuing work started with PR PHPOffice#4016, PR PHPOffice#4026, and PR PHPOffice#4060. Improve documentation within program by making explicit what types of values are allowed for variables described as "mixed". In order to avoid broken functionality, this is done mainly through doc-blocks. This will get us closer to Phpstan Level 9, but many changes will be needed before we can consider that. After this PR, all the remaining changes will be in src/Calculation.
1 parent f7c183b commit fdd9f8c

File tree

9 files changed

+75
-46
lines changed

9 files changed

+75
-46
lines changed

src/PhpSpreadsheet/Cell/Cell.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function getFormattedValue(): string
191191
$currentCalendar = SharedDate::getExcelCalendar();
192192
SharedDate::setExcelCalendar($this->getWorksheet()->getParent()?->getExcelCalendar());
193193
$formattedValue = (string) NumberFormat::toFormattedString(
194-
$this->getCalculatedValue(),
194+
$this->getCalculatedValueString(),
195195
(string) $this->getStyle()->getNumberFormat()->getFormatCode(true)
196196
);
197197
SharedDate::setExcelCalendar($currentCalendar);
@@ -920,7 +920,7 @@ public function setXfIndex(int $indexValue): self
920920
*
921921
* @return $this
922922
*/
923-
public function setFormulaAttributes(mixed $attributes): self
923+
public function setFormulaAttributes(null|array $attributes): self
924924
{
925925
$this->formulaAttributes = $attributes;
926926

src/PhpSpreadsheet/Reader/Xlsx.php

+63-37
Large diffs are not rendered by default.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public function testTooMuchPrecision(mixed $expectedResult, float|int|string $va
6060
$sheet = $this->getSheet();
6161
$sheet->getCell('E1')->setValue($value);
6262
$sheet->getCell('E2')->setValue("=TRUNC(E1,$digits)");
63-
$result = $sheet->getCell('E2')->getCalculatedValue();
64-
self::assertSame($expectedResult, (string) $result);
63+
$result = $sheet->getCell('E2')->getCalculatedValueString();
64+
self::assertSame($expectedResult, $result);
6565
}
6666

6767
public static function providerTooMuchPrecision(): array

tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function testCONCATENATE(mixed $expectedResult, mixed ...$args): void
3030
$finalArg .= 'A3';
3131
$sheet->getCell('A3')->setValue(str_repeat('Ԁ', DataType::MAX_STRING_LENGTH - 5));
3232
} else {
33+
self::assertTrue($arg === null || is_scalar($arg));
3334
$finalArg .= '"' . (string) $arg . '"';
3435
}
3536
}

tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormula2Test.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testArrayFormulaReader(
2626
$cell = $worksheet->getCell($cellAddress);
2727
self::assertSame(DataType::TYPE_FORMULA, $cell->getDataType());
2828
self::assertSame(['t' => 'array', 'ref' => $expectedRange], $cell->getFormulaAttributes());
29-
self::assertSame($expectedFormula, strtoupper($cell->getValue()));
29+
self::assertSame($expectedFormula, strtoupper($cell->getValueString()));
3030
Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);
3131
$worksheet->calculateArrays();
3232
$cell = $worksheet->getCell($cellAddress);

tests/PhpSpreadsheetTests/Reader/Gnumeric/ArrayFormulaTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testArrayFormulaReader(
3030
} else {
3131
self::assertEmpty($cell->getFormulaAttributes());
3232
}
33-
self::assertSame($expectedFormula, strtoupper($cell->getValue()));
33+
self::assertSame($expectedFormula, strtoupper($cell->getValueString()));
3434
Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);
3535
$worksheet->calculateArrays();
3636
$cell = $worksheet->getCell($cellAddress);

tests/PhpSpreadsheetTests/Reader/Ods/ArrayFormulaTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testArrayFormulaReader(
2626
$cell = $worksheet->getCell($cellAddress);
2727
self::assertSame(DataType::TYPE_FORMULA, $cell->getDataType());
2828
self::assertSame(['t' => 'array', 'ref' => $expectedRange], $cell->getFormulaAttributes());
29-
self::assertSame($expectedFormula, strtoupper($cell->getValue()));
29+
self::assertSame($expectedFormula, strtoupper($cell->getValueString()));
3030
Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);
3131
$worksheet->calculateArrays();
3232
$cell = $worksheet->getCell($cellAddress);

tests/PhpSpreadsheetTests/Reader/Xml/ArrayFormulaTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function testArrayFormulaReader(): void
1717

1818
self::assertSame(DataType::TYPE_FORMULA, $sheet->getCell('B1')->getDataType());
1919
self::assertSame(['t' => 'array', 'ref' => 'B1:B3'], $sheet->getCell('B1')->getFormulaAttributes());
20-
self::assertSame('=CONCATENATE(A1:A3,"-",C1:C3)', strtoupper($sheet->getCell('B1')->getValue()));
20+
self::assertSame('=CONCATENATE(A1:A3,"-",C1:C3)', strtoupper($sheet->getCell('B1')->getValueString()));
2121
self::assertSame('a-1', $sheet->getCell('B1')->getOldCalculatedValue());
2222
self::assertSame('b-2', $sheet->getCell('B2')->getValue());
2323
self::assertSame('c-3', $sheet->getCell('B3')->getValue());

tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctions2Test.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ public function testManyArraysOutput(): void
268268
{
269269
$json = file_get_contents('tests/data/Writer/XLSX/ArrayFunctions2.json');
270270
self::assertNotFalse($json);
271-
$this->trn = json_decode($json, true);
271+
$trn = json_decode($json, true);
272+
self::assertIsArray($trn);
273+
$this->trn = $trn;
272274
$spreadsheet = new Spreadsheet();
273275
Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);
274276

0 commit comments

Comments
 (0)