Mutagenesis\Mutable::_parseMutables PHP 메소드

_parseMutables() 보호된 메소드

Parse the given file into an array of method metainformation including class name, method name, file name, method arguments, and method body tokens.
protected _parseMutables ( ) : array
리턴 array
    protected function _parseMutables()
    {
        $tokens = token_get_all(file_get_contents($this->getFilename()));
        $inblock = false;
        $inarg = false;
        $curlycount = 0;
        $roundcount = 0;
        $blockTokens = array();
        $argTokens = array();
        $methods = array();
        $mutable = array();
        $static = false;
        $staticClassCapture = true;
        foreach ($tokens as $index => $token) {
            if (is_array($token) && $token[0] == T_STATIC && $staticClassCapture === true) {
                $static = true;
                $staticClassCapture = false;
                continue;
            }
            // get class name
            if (is_array($token) && ($token[0] == T_CLASS || $token[0] == T_INTERFACE)) {
                $className = $tokens[$index + 2][1];
                $staticClassCapture = false;
                continue;
            }
            // get method name
            if (is_array($token) && $token[0] == T_FUNCTION) {
                $methodName = $tokens[$index + 2][1];
                $inarg = true;
                $mutable = array('file' => $this->getFilename(), 'class' => $className, 'method' => $methodName);
                continue;
            }
            // Get the method's parameter string
            if ($inarg) {
                if ($token == '(') {
                    $roundcount += 1;
                } elseif ($token == ')') {
                    $roundcount -= 1;
                }
                if ($roundcount == 1 && $token == '(') {
                    continue;
                } elseif ($roundcount >= 1) {
                    $argTokens[] = $token;
                } elseif ($roundcount == 0) {
                    $mutable['args'] = $this->_reconstructFromTokens($argTokens);
                    $argTokens = array();
                    $inarg = false;
                    $inblock = true;
                }
                continue;
            }
            // Get the method's block code
            if ($inblock) {
                if ($token == '{') {
                    $curlycount += 1;
                } elseif ($token == '}') {
                    $curlycount -= 1;
                }
                if ($curlycount == 1 && $token == '{') {
                    continue;
                } elseif ($curlycount >= 1) {
                    if (is_array($token) && $token[0] == 370) {
                        continue;
                    }
                    $blockTokens[] = $token;
                } elseif ($curlycount == 0 && count($blockTokens) > 0) {
                    $mutable['tokens'] = $blockTokens;
                    $methods[] = $mutable;
                    $mutable = array();
                    $blockTokens = array();
                    $inblock = false;
                    $staticClassCapture = true;
                }
            }
        }
        return $methods;
    }