Exakat\Tasks\FindExternalLibraries::process PHP Method

process() private method

private process ( $filename )
    private function process($filename)
    {
        $return = array();
        $tokens = $this->php->getTokenFromFile($filename);
        if (count($tokens) == 1) {
            return $return;
        }
        $this->log->log("{$filename} : " . count($tokens));
        foreach ($tokens as $id => $token) {
            if (is_string($token)) {
                continue;
            }
            if ($token[0] == T_WHITESPACE) {
                continue;
            }
            if ($token[0] == T_DOC_COMMENT) {
                continue;
            }
            if ($token[0] == T_COMMENT) {
                continue;
            }
            // If we find a namespace, it is not the global space, and we may skip the rest.
            if ($token[0] == T_NAMESPACE) {
                return;
            }
            if ($token[0] == T_CLASS) {
                if (!is_array($tokens[$id + 2])) {
                    continue;
                }
                $class = $tokens[$id + 2][1];
                if (!is_string($class)) {
                    // ignoring errors in the parsed code. Should go to log.
                    continue;
                }
                $lclass = strtolower($class);
                if (isset($this->classic[$lclass])) {
                    if ($this->classic[$lclass] == static::WHOLE_DIR) {
                        $returnPath = dirname(preg_replace('#.*projects/.*?/code/#', '/', $filename));
                    } elseif ($this->classic[$lclass] == static::PARENT_DIR) {
                        $returnPath = dirname(dirname(preg_replace('#.*projects/.*?/code/#', '/', $filename)));
                    } elseif ($this->classic[$lclass] == static::FILE_ONLY) {
                        $returnPath = preg_replace('#.*projects/.*?/code/#', '/', $filename);
                    }
                    if ($returnPath != '/') {
                        $return[$class] = $returnPath;
                    }
                }
                if (is_array($tokens[$id + 4]) && $tokens[$id + 4][0] == T_EXTENDS) {
                    $ix = $id + 6;
                    $extends = '';
                    while ($tokens[$ix][0] == T_NS_SEPARATOR || $tokens[$ix][0] == T_STRING) {
                        $extends .= $tokens[$ix][1];
                        ++$ix;
                    }
                    $extends = trim(strtolower($extends), '\\');
                    if (isset($this->classicTests[$extends])) {
                        if ($this->classicTests[$extends] == static::WHOLE_DIR) {
                            $returnPath = dirname(preg_replace('#.*projects/.*?/code/#', '/', $filename));
                        } elseif ($this->classicTests[$extends] == static::PARENT_DIR) {
                            $returnPath = dirname(dirname(preg_replace('#.*projects/.*?/code/#', '/', $filename)));
                        } elseif ($this->classicTests[$extends] == static::FILE_ONLY) {
                            $returnPath = preg_replace('#.*projects/.*?/code/#', '/', $filename);
                        }
                        if ($returnPath != '/') {
                            $return[$class] = $returnPath;
                        }
                    }
                }
            }
        }
        return $return;
    }
FindExternalLibraries