Exakat\Tasks\Load::processArguments PHP Method

processArguments() private method

private processArguments ( $finals = [T_CLOSE_PARENTHESIS], $typehint = false )
    private function processArguments($finals = array(T_CLOSE_PARENTHESIS), $typehint = false)
    {
        $argumentsId = $this->addAtom('Arguments');
        $current = $this->id;
        $this->argumentsId = array();
        $this->nestContext();
        $fullcode = array();
        if (in_array($this->tokens[$this->id + 1][0], array(T_CLOSE_PARENTHESIS, T_CLOSE_BRACKET))) {
            $voidId = $this->addAtomVoid();
            $this->setAtom($voidId, array('rank' => 0));
            $this->addLink($argumentsId, $voidId, 'ARGUMENT');
            $this->setAtom($argumentsId, array('code' => $this->tokens[$current][1], 'fullcode' => self::FULLCODE_VOID, 'line' => $this->tokens[$current][2], 'token' => $this->getToken($this->tokens[$current][0]), 'count' => 0, 'args_max' => 0, 'args_min' => 0));
            $this->argumentsId[] = $voidId;
            ++$this->id;
        } else {
            $typehintId = 0;
            $defaultId = 0;
            $indexId = 0;
            $args_max = 0;
            $args_min = 0;
            $rank = -1;
            while (!in_array($this->tokens[$this->id + 1][0], $finals)) {
                ++$args_max;
                if ($typehint === true) {
                    if ($this->tokens[$this->id + 1][0] === T_QUESTION) {
                        $nullableId = $this->processNextAsIdentifier();
                    } else {
                        $nullableId = 0;
                    }
                    $typehintId = $this->processTypehint();
                    $this->processNext();
                    $indexId = $this->popExpression();
                    if ($this->tokens[$this->id + 1][0] === T_EQUAL) {
                        ++$this->id;
                        // Skip =
                        while (!in_array($this->tokens[$this->id + 1][0], array(T_COMMA, T_CLOSE_PARENTHESIS, T_CLOSE_BRACKET))) {
                            $this->processNext();
                        }
                        $defaultId = $this->popExpression();
                    } else {
                        ++$args_min;
                        $defaultId = 0;
                    }
                } else {
                    $typehintId = 0;
                    $defaultId = 0;
                    $nullableId = 0;
                    while (!in_array($this->tokens[$this->id + 1][0], array(T_COMMA, T_CLOSE_PARENTHESIS, T_SEMICOLON, T_CLOSE_BRACKET, T_CLOSE_TAG))) {
                        $this->processNext();
                    }
                    $indexId = $this->popExpression();
                }
                while ($this->tokens[$this->id + 1][0] === T_COMMA) {
                    if ($indexId === 0) {
                        $indexId = $this->addAtomVoid();
                    }
                    $this->setAtom($indexId, array('rank' => ++$rank));
                    $this->argumentsId[] = $indexId;
                    if ($nullableId > 0) {
                        $this->addLink($indexId, $nullableId, 'NULLABLE');
                        $this->addLink($indexId, $typehintId, 'TYPEHINT');
                        $this->setAtom($indexId, array('fullcode' => '?' . $this->atoms[$typehintId]['fullcode'] . ' ' . $this->atoms[$indexId]['fullcode']));
                    } elseif ($typehintId > 0) {
                        $this->addLink($indexId, $typehintId, 'TYPEHINT');
                        $this->setAtom($indexId, array('fullcode' => $this->atoms[$typehintId]['fullcode'] . ' ' . $this->atoms[$indexId]['fullcode']));
                    }
                    if ($defaultId > 0) {
                        $this->addLink($indexId, $defaultId, 'DEFAULT');
                        $this->setAtom($indexId, array('fullcode' => $this->atoms[$indexId]['fullcode'] . ' = ' . $this->atoms[$defaultId]['fullcode']));
                        $defaultId = 0;
                    }
                    $this->addLink($argumentsId, $indexId, 'ARGUMENT');
                    $fullcode[] = $this->atoms[$indexId]['fullcode'];
                    ++$this->id;
                    // Skipping the comma ,
                    $indexId = 0;
                }
            }
            if ($indexId === 0) {
                $indexId = $this->addAtomVoid();
            }
            $this->setAtom($indexId, array('rank' => ++$rank));
            $this->argumentsId[] = $indexId;
            if ($nullableId > 0) {
                $this->addLink($indexId, $nullableId, 'NULLABLE');
                $this->addLink($indexId, $typehintId, 'TYPEHINT');
                $this->setAtom($indexId, array('fullcode' => '?' . $this->atoms[$typehintId]['fullcode'] . ' ' . $this->atoms[$indexId]['fullcode']));
            } elseif ($typehintId > 0) {
                $this->addLink($indexId, $typehintId, 'TYPEHINT');
                $this->setAtom($indexId, array('fullcode' => $this->atoms[$typehintId]['fullcode'] . ' ' . $this->atoms[$indexId]['fullcode']));
            }
            if ($defaultId > 0) {
                $this->addLink($indexId, $defaultId, 'DEFAULT');
                $this->setAtom($indexId, array('fullcode' => $this->atoms[$indexId]['fullcode'] . ' = ' . $this->atoms[$defaultId]['fullcode']));
            }
            $this->addLink($argumentsId, $indexId, 'ARGUMENT');
            $fullcode[] = $this->atoms[$indexId]['fullcode'];
            // Skip the )
            ++$this->id;
            $this->setAtom($argumentsId, array('code' => $this->tokens[$current][1], 'fullcode' => implode(', ', $fullcode), 'line' => $this->tokens[$current][2], 'token' => 'T_COMMA', 'count' => $rank + 1, 'args_max' => $args_max, 'args_min' => $args_min));
        }
        $this->exitContext();
        return $argumentsId;
    }
Load