Files
oleibman a3f3d2c9ad Clean Up Documentation for Worksheet (#3281)
* Clean Up Documentation for Worksheet

This PR was intended to clean up Phpstan/Scrutinizer messages regarding Worksheet. It is, for the most part, straightforward, but there is one problem which complicates things. The frequently-called public method `getParent` returns `Worksheet` or `null` but is documented to return only `Worksheet`. This can be addressed in either of two ways - change the code to match the documentation (smaller number of changes but a backwards compatibility break), or change the documentation to match the code (larger number of changes but no compatibility break). I have prepared a PR for each approach, but avoiding a compatibility break seems better, so I am pushing the latter. I can switch to the other if preferred. Most existing internal calls to `getParent` are changed to use a new method `getParentOrThrow`, which will throw an exception if parent is null. These calls would all have thrown a null pointer exception anyhow in that situation, so this should not cause any new breaks.

* Scrutinizer

One false positive, and one message leading to a minor code improvement.
2023-01-11 23:34:52 -08:00

45 lines
2.6 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information;
use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef\AllSetupTeardown;
class IsRefTest extends AllSetupTeardown
{
public function testIsRef(): void
{
$sheet = $this->getSheet();
$sheet->getParentOrThrow()->addDefinedName(new NamedRange('NAMED_RANGE', $sheet, 'C1'));
$sheet->getCell('A1')->setValue('=ISREF(B1)');
$sheet->getCell('A2')->setValue('=ISREF(B1:B2)');
$sheet->getCell('A3')->setValue('=ISREF(B1:D4 C1:C5)');
$sheet->getCell('A4')->setValue('=ISREF("PHP")');
$sheet->getCell('A5')->setValue('=ISREF(B1*B2)');
$sheet->getCell('A6')->setValue('=ISREF(Worksheet2!B1)');
$sheet->getCell('A7')->setValue('=ISREF(NAMED_RANGE)');
$sheet->getCell('A8')->setValue('=ISREF(INDIRECT("' . $sheet->getTitle() . '" & "!" & "A1"))');
$sheet->getCell('A9')->setValue('=ISREF(INDIRECT("A1"))');
$sheet->getCell('A10')->setValue('=ISREF(INDIRECT("Invalid Worksheet" & "!" & "A1"))');
$sheet->getCell('A11')->setValue('=ISREF(INDIRECT("Invalid Worksheet" & "!A1"))');
$sheet->getCell('A12')->setValue('=ISREF(ZZZ1)');
$sheet->getCell('A13')->setValue('=ISREF(CHOOSE(2, A1, B1, C1))');
self::assertTrue($sheet->getCell('A1')->getCalculatedValue()); // Cell Reference
self::assertTrue($sheet->getCell('A2')->getCalculatedValue()); // Cell Range
self::assertTrue($sheet->getCell('A3')->getCalculatedValue()); // Complex Cell Range
self::assertFalse($sheet->getCell('A4')->getCalculatedValue()); // Text String
self::assertFalse($sheet->getCell('A5')->getCalculatedValue()); // Result of a math expression
self::assertTrue($sheet->getCell('A6')->getCalculatedValue()); // Cell Reference with worksheet
self::assertTrue($sheet->getCell('A7')->getCalculatedValue()); // Named Range
self::assertTrue($sheet->getCell('A8')->getCalculatedValue()); // Indirect to a Cell Reference
self::assertTrue($sheet->getCell('A9')->getCalculatedValue()); // Indirect to a Worksheet/Cell Reference
self::assertFalse($sheet->getCell('A10')->getCalculatedValue()); // Indirect to an Invalid Worksheet/Cell Reference
self::assertFalse($sheet->getCell('A11')->getCalculatedValue()); // Indirect to an Invalid Worksheet/Cell Reference
self::assertFalse($sheet->getCell('A12')->getCalculatedValue()); // Invalid Cell Reference
self::assertTrue($sheet->getCell('A13')->getCalculatedValue()); // returned Cell Reference
}
}