FormulaHelper::processFormula()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 14
cp 0
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 4
crap 6
1
<?php
2
namespace Mathielen\ReportWriteEngine\Utils;
3
4
class FormulaHelper
5
{
6
7
    public static function processFormula($cellValue, $rangeCellValue, $currentRowNum, $rangeRowNum)
8
    {
9
        if (substr($rangeCellValue, 0, 1) == '=') {
10
            $rowDelta = $currentRowNum + $rangeRowNum;
11
            //has ref to field - add row-offset
12
            $cellValue = preg_replace_callback(
13
                '/([A-Z]+)([0-9])+/',
14
                function ($matches) use ($rowDelta) {
15
                    $offsettedY = ($matches[2] + $rowDelta);
16
17
                    return $matches[1] . $offsettedY;
18
                },
19
                $cellValue);
20
        }
21
22
        return $cellValue;
23
    }
24
}
25