src/Jit/Patcher/Monkey.php
protected function _addClosingParenthesis($pos, $index, $parent)
    {
        $count = 0;
        $nodes = $parent->tree;
        $total = count($nodes);

        for ($i = $index; $i < $total; $i++) {
            $node = $nodes[$i];

            if (!$node->processable || $node->type !== 'code') {
                if (!$node->close) {
                    continue;
                }
                $code = &$node->close;
            } else {
                $code = &$node->body;
            }

            $len = strlen($code);

            while ($pos < $len) {
                if ($count === 0 && $code[$pos] === ';') {
                    $code = substr_replace($code, ');', $pos, 1);
                    return true;
                } elseif ($code[$pos] === '(') {
                    $count++;
                } elseif ($code[$pos] === ')') {
                    $count--;
                    if ($count === 0) {
                        $code = substr_replace($code, $code[$pos] . ')', $pos, 1);
                        return true;
                    }
                }
                $pos++;
            }
            $pos = 0;
        }
        return false;
    }
protected function _addClosingParenthesis($pos, $index, $parent)
    {
        $count = 0;
        $nodes = $parent->tree;
        $total = count($nodes);

        for ($i = $index; $i < $total; $i++) {
            $node = $nodes[$i];

            if (!$node->processable || $node->type !== 'code') {
                if (!$node->close) {
                    continue;
                }
                $code = &$node->close;
            } else {
                $code = &$node->body;
            }

            $len = strlen($code);

            while ($pos < $len) {
                if ($count === 0 && $code[$pos] === ';') {
                    $code = substr_replace($code, ');', $pos, 1);
                    return true;
                } elseif ($code[$pos] === '(') {
                    $count++;
                } elseif ($code[$pos] === ')') {
                    $count--;
                    if ($count === 0) {
                        $code = substr_replace($code, $code[$pos] . ')', $pos, 1);
                        return true;
                    }
                }
                $pos++;
            }
            $pos = 0;
        }
        return false;
    }
protected function _addClosingParenthesis ( $ pos , $ index , $ parent ) { $ count = 0 ; $ nodes = $ parent -> tree ; $ total = count ( $ nodes ) ; for ( $ i = $ index ; $ i < $ total ; $ i ++ ) { $ node = $ nodes [ $ i ] ; if ( ! $ node -> processable || $ node -> type !== 'code' ) { if ( ! $ node -> close ) { continue ; } $ code = & $ node -> close ; } else { $ code = & $ node -> body ; } $ len = strlen ( $ code ) ; while ( $ pos < $ len ) { if ( $ count === 0 && $ code [ $ pos ] === ';' ) { $ code = substr_replace ( $ code , ');' , $ pos , 1 ) ; return true ; } elseif ( $ code [ $ pos ] === '(' ) { $ count ++ ; } elseif ( $ code [ $ pos ] === ')' ) { $ count -- ; if ( $ count === 0 ) { $ code = substr_replace ( $ code , $ code [ $ pos ] . ')' , $ pos , 1 ) ; return true ; } } $ pos ++ ; } $ pos = 0 ; } return false ; }
Add a closing parenthesis

@param object  $node   The node to monkey patch.
@param array   $parent The parent array.
@param integer $index  The index of node in parent children.
@return boolean        Returns `true` if succeed, `false` otherwise.
Add a closing parenthesis