Conditions | 4 |
Paths | 4 |
Total Lines | 22 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 4.0039 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | 9 | public static function fromParser(string $formula, int $index, array $matches): self |
|
22 | { |
||
23 | 9 | $val = $matches[0]; |
|
24 | |||
25 | 9 | $srCount = substr_count($val, self::OPEN_BRACE) |
|
26 | 9 | - substr_count($val, self::CLOSE_BRACE); |
|
27 | 9 | while ($srCount > 0) { |
|
28 | 9 | $srIndex = strlen($val); |
|
29 | 9 | $srStringRemainder = substr($formula, $index + $srIndex); |
|
30 | 9 | $closingPos = strpos($srStringRemainder, self::CLOSE_BRACE); |
|
31 | 9 | if ($closingPos === false) { |
|
32 | throw new Exception("Formula Error: No closing ']' to match opening '['"); |
||
33 | } |
||
34 | 9 | $srStringRemainder = substr($srStringRemainder, 0, $closingPos + 1); |
|
35 | 9 | --$srCount; |
|
36 | 9 | if (strpos($srStringRemainder, self::OPEN_BRACE) !== false) { |
|
37 | 7 | ++$srCount; |
|
38 | } |
||
39 | 9 | $val .= $srStringRemainder; |
|
40 | } |
||
41 | |||
42 | 9 | return new self($val); |
|
43 | } |
||
50 |