Code Duplication    Length = 6-7 lines in 3 locations

src/PhpSpreadsheet/Calculation.php 3 locations

@@ 3130-3136 (lines=7) @@
3127
                $expectingOperator = false;
3128
            } elseif ($opCharacter == ')' && $expectingOperator) {            //    Are we expecting to close a parenthesis?
3129
                $expectingOperand = false;
3130
                while (($o2 = $stack->pop()) && $o2['value'] != '(') {        //    Pop off the stack back to the last (
3131
                    if ($o2 === null) {
3132
                        return $this->raiseFormulaError('Formula Error: Unexpected closing brace ")"');
3133
                    } else {
3134
                        $output[] = $o2;
3135
                    }
3136
                }
3137
                $d = $stack->last(2);
3138
                if (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/i', $d['value'], $matches)) {    //    Did this parenthesis just close a function?
3139
                    $functionName = $matches[1]; //    Get the function name
@@ 3196-3202 (lines=7) @@
3193
                }
3194
                ++$index;
3195
            } elseif ($opCharacter == ',') {            //    Is this the separator for function arguments?
3196
                while (($o2 = $stack->pop()) && $o2['value'] != '(') {        //    Pop off the stack back to the last (
3197
                    if ($o2 === null) {
3198
                        return $this->raiseFormulaError('Formula Error: Unexpected ,');
3199
                    } else {
3200
                        $output[] = $o2; // pop the argument expression stuff and push onto the output
3201
                    }
3202
                }
3203
                //    If we've a comma when we're expecting an operand, then what we actually have is a null operand;
3204
                //        so push a null onto the stack
3205
                if (($expectingOperand) || (!$expectingOperator)) {
@@ 3372-3377 (lines=6) @@
3369
            }
3370
        }
3371
3372
        while (($op = $stack->pop()) !== null) {    // pop everything off the stack and push onto output
3373
            if ((is_array($op) && $op['value'] == '(') || ($op === '(')) {
3374
                return $this->raiseFormulaError("Formula Error: Expecting ')'"); // if there are any opening braces on the stack, then braces were unbalanced
3375
            }
3376
            $output[] = $op;
3377
        }
3378
3379
        return $output;
3380
    }