Exakat\Tasks\Load::processIfthen PHP Method

processIfthen() private method

private processIfthen ( )
    private function processIfthen()
    {
        $id = $this->addAtom('Ifthen');
        $current = $this->id;
        ++$this->id;
        // Skip (
        while (!in_array($this->tokens[$this->id + 1][0], array(T_CLOSE_PARENTHESIS))) {
            $this->processNext();
        }
        $conditionId = $this->popExpression();
        $this->addLink($id, $conditionId, 'CONDITION');
        ++$this->id;
        // Skip )
        $isInitialIf = $this->tokens[$current][0] === T_IF;
        $isColon = $this->tokens[$this->id + 1][0] === T_COLON;
        $thenId = $this->processFollowingBlock(array(T_ENDIF, T_ELSE, T_ELSEIF));
        $this->popExpression();
        $this->addLink($id, $thenId, 'THEN');
        // Managing else case
        if (in_array($this->tokens[$this->id][0], array(T_END, T_CLOSE_TAG))) {
            $else = '';
            // No else, end of a script
            --$this->id;
            // Back up one unit to allow later processing for sequence
        } elseif ($this->tokens[$this->id + 1][0] === T_ELSEIF) {
            ++$this->id;
            $elseifId = $this->processIfthen();
            $this->addLink($id, $elseifId, 'ELSE');
            $else = $this->atoms[$elseifId]['fullcode'];
        } elseif ($this->tokens[$this->id + 1][0] === T_ELSE) {
            $else = $this->tokens[$this->id + 1][1];
            ++$this->id;
            // Skip else
            $elseId = $this->processFollowingBlock(array(T_ENDIF));
            $this->popExpression();
            $this->addLink($id, $elseId, 'ELSE');
            if ($isColon === true) {
                $else .= ' :';
            }
            $else .= $this->atoms[$elseId]['fullcode'];
        } else {
            $else = '';
        }
        if ($isInitialIf === true && $isColon === true) {
            if ($this->tokens[$this->id + 1][0] === T_SEMICOLON) {
                ++$this->id;
                // skip ;
            }
            ++$this->id;
            // skip ;
        }
        if ($isColon) {
            $fullcode = $this->tokens[$current][1] . '(' . $this->atoms[$conditionId]['fullcode'] . ') : ' . $this->atoms[$thenId]['fullcode'] . $else . ($isInitialIf === true ? ' endif' : '');
        } else {
            $fullcode = $this->tokens[$current][1] . '(' . $this->atoms[$conditionId]['fullcode'] . ')' . $this->atoms[$thenId]['fullcode'] . $else;
        }
        if ($this->tokens[$current][0] === T_IF) {
            $this->pushExpression($id);
            $this->processSemicolon();
        }
        if ($this->tokens[$this->id][0] === T_CLOSE_TAG) {
            --$this->id;
        }
        $this->setAtom($id, array('code' => $this->tokens[$current][1], 'fullcode' => $fullcode, 'line' => $this->tokens[$current][2], 'token' => $this->getToken($this->tokens[$current][0]), 'alternative' => $isColon));
        return $id;
    }
Load