Passed
Push — master ( 8a61a1...4323fc )
by
unknown
20:10 queued 40s
created

Formula   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 7
eloc 17
dl 0
loc 33
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B text() 0 25 7
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
6
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
7
use PhpOffice\PhpSpreadsheet\Cell\Cell;
8
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
9
10
class Formula
11
{
12
    /**
13
     * FORMULATEXT.
14
     *
15
     * @param mixed $cellReference The cell to check
16
     * @param ?Cell $cell The current cell (containing this formula)
17
     */
18 11
    public static function text(mixed $cellReference = '', ?Cell $cell = null): string
19
    {
20 11
        if ($cell === null) {
21 1
            return ExcelError::REF();
22
        }
23
24 10
        $worksheet = null;
25 10
        $cellReference = StringHelper::convertToString($cellReference);
26 10
        if (1 === preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches)) {
27 10
            $cellReference = $matches[6] . $matches[7];
28 10
            $worksheetName = trim($matches[3], "'");
29 10
            $worksheet = (!empty($worksheetName))
30 10
                ? $cell->getWorksheet()->getParentOrThrow()->getSheetByName($worksheetName)
31
                : $cell->getWorksheet();
32
        }
33
34
        if (
35 10
            $worksheet === null
36 10
            || !$worksheet->cellExists($cellReference)
37 10
            || !$worksheet->getCell($cellReference)->isFormula()
38
        ) {
39 3
            return ExcelError::NA();
40
        }
41
42 7
        return $worksheet->getCell($cellReference)->getValueString();
43
    }
44
}
45