return all in file use statement defined classes

@param string $classFile absolute path of readable class file

@return array
978613
public function getUsedClassesInClass($classFile)
    {
        $useResult = array();
        $content = $this->getFileContent($classFile);
        if (preg_match_all('/(use\s+)(.*)(;)/', $content, $useResult) && 4 === count($useResult)) {
            // @todo: use keyName based result check instead of index!
            return ($useResult[2]);
        }

        return null;
    }
1131758
public static function getAllClassTraits($class)
    {
        $results = [];

        foreach (array_merge([$class => $class], class_parents($class)) as $class) {
            $results += self::getAllTraits($class);
        }

        return array_unique($results);
    }
1288609
public static function getClassesFromFile($file)
    {
        $php = \File::get($file);
        $classes = array();
        $tokens = token_get_all($php);
        $count = count($tokens);
        for ($i = 2; $i < $count; $i++) {
            if ($tokens[$i - 2][0] == T_CLASS
                && $tokens[$i - 1][0] == T_WHITESPACE
                && $tokens[$i][0] == T_STRING
            ) {
                $class_name = $tokens[$i][1];
                $namespace = self::getNamespace($tokens);
                $classes[] = $namespace . "\\" . $class_name;
            }
        }
        return $classes;
    }
1228654
protected function getNamespace(File $phpCsFile): string
    {
        $className = $this->getClassName($phpCsFile);
        $classNameParts = explode('\\', $className);

        return $classNameParts[0];
    }
606807
public static function getAllProperties($class, $blacklist = [])
    {
        $classReflection = new \ReflectionClass($class);

        $properties = $classReflection->getProperties();

        if ($parentClass = $classReflection->getParentClass()) {
            $parentProps = self::getAllProperties($parentClass->getName(), $blacklist);
            if (!empty($parentProps)) {
                $properties = array_merge($parentProps, $properties);
            }
        }
        if (empty($blacklist)) {
            return $properties;
        }

        return array_filter(
            $properties,
            function (\ReflectionProperty $property) use ($blacklist) {
                return !$property->isStatic() && !in_array($property->name, $blacklist);
            }
        );
    }
917603
public function getExactlyOneClass($fileSource) {
        if (count($this->ast) !== 1 || $this->ast[0]->getType() !== "Stmt_Class")
            throw new PhpParserException("\"$fileSource\" does not define exactly one class");
        return $this->ast[0];
    }
693070
public function definedClasses() {
        $loops = $this->getLoops();

        $cache = $loops->getService("cache");

        $key = "Loops-Application-definedClasses";

        if($cache->contains($key)) {
            return $cache->fetch($key);
        }

        $require = function($dir) use (&$require, &$classes) {
            foreach(scandir($dir) as $file) {
                if(substr($file, 0, 1) == '.') {
                    continue;
                }

                $filename = "$dir/$file";

                if(is_dir($filename)) {
                    $require($filename);
                }
                else {
                    require_once($filename);
                }
            }
        };

        $dirs = $this->include_dir;

        array_walk($dirs, $require);

        $classes = array_values(array_filter(get_declared_classes(), function($classname) use ($dirs, $cache) {
            $reflection = new ReflectionClass($classname);
            $filename = $reflection->getFileName();

            if(!$filename) {
                return FALSE;
            }

            if($this->enable_cached_autoload) {
                $key = "Loops-Application-autoload-$classname";
                $cache->save($key, $filename);
            }

            foreach($dirs as $dir) {
                if(substr($filename, 0, strlen($dir)) == $dir) {
                    return TRUE;
                }
            }

            return FALSE;
        }));

        $cache->save($key, $classes);

        return $classes;
    }
438714
public function reflect(string $classOrFile): array
    {
        $className = $this->classFileNormalizer->normalizeToClass($classOrFile);
        $reflection = $this->reflector->reflectClassLike(ClassName::fromString($className));

        $return  = [
            'class' => (string) $reflection->name(),
            'class_namespace' => (string) $reflection->name()->namespace(),
            'class_name' => (string) $reflection->name()->short(),
            'methods' => [],
            'properties' => [],
            'constants' => [],
        ];


        /** @var $method ReflectionMethod */
        foreach ($reflection->methods() as $method) {
            $methodInfo = [
                (string) $method->visibility() . ' function ' . $method->name()
            ];

            $return['methods'][$method->name()] = [
                'name' => $method->name(),
                'abstract' => $method->isAbstract(),
                'visibility' => (string) $method->visibility(),
                'parameters' => [],
                'static' => $method->isStatic() ? 1 : 0
            ];

            $paramInfos = [];
            /** @var $parameter ReflectionParameter */
            foreach ($method->parameters() as $parameter) {
                $parameterType = $parameter->type();
                // build parameter synopsis
                $paramInfo = [];
                if ($parameter->type()->isDefined()) {
                    $paramInfo[] = $parameterType->className() ?: (string) $parameterType;
                }
                $paramInfo[] = '$' . $parameter->name();
                if ($parameter->default()->isDefined()) {
                    $paramInfo[] = ' = ' . str_replace(PHP_EOL, '', var_export($parameter->default()->value(), true));
                }
                $paramInfos[] = implode(' ', $paramInfo);

                $return['methods'][$method->name()]['parameters'][$parameter->name()] = [
                    'name' => $parameter->name(),
                    'has_type' => $parameter->type()->isDefined(),
                    'type' => $parameter->type()->isDefined() ? ($parameterType->className() ? $parameterType->className()->short(): (string) $parameterType) : null,
                    'has_default' => $parameter->default()->isDefined(),
                    'default' => $parameter->default()->value(),
                ];
            }

            $methodInfo[] = '(' . implode(', ', $paramInfos) . ')';
            $methodType = $method->returnType();

            if (Type::unknown() != $methodType) {
                $methodInfo[] = ': ' . ($methodType->isPrimitive() ? (string) $methodType : $methodType->className()->short());
            }

            $return['methods'][$method->name()]['type'] = $methodType->isDefined() ? $methodType->short() : null;

            $return['methods'][$method->name()]['synopsis'] = implode('', $methodInfo);
            $return['methods'][$method->name()]['docblock'] = $method->docblock()->formatted();
        }

        if (false === $reflection->isTrait()) {
            /** @var $constant ReflectionConstant */
            foreach ($reflection->constants() as $constant) {
                $return['constants'][$constant->name()] = [
                    'name' => $constant->name()
                ];
            }
        }


        if (!$reflection instanceof ReflectionClass) {
            return $return;
        }

        /** @var $property ReflectionProperty */
        foreach ($reflection->properties() as $property) {
            $propertyType = $property->inferredTypes()->best();
            $return['properties'][$property->name()] = [
                'name' => $property->name(),
                'visibility' => (string) $property->visibility(),
                'static' => $property->isStatic() ? 1 : 0,
                'info' => sprintf(
                    '%s %s $%s',
                    (string) $property->visibility(),
                    $propertyType->isPrimitive() ? (string) $propertyType : (string) $propertyType->className(),
                    $property->name()
                ),
            ];
        }

        return $return;
    }
856872
public function findClasses()
    {
        $files = $this->getFiles($this->searchPath);

        // if class are not loaded they will ne be caught by "declared_classes"
        $this->loadFiles($files);

        return $this->identifyClasses();
    }
199130
protected function parseUseStatements(File $phpCsFile, int $stackPointer): array
    {
        $useStatements = [];
        $tokens = $phpCsFile->getTokens();
        if ($phpCsFile->findPrevious(T_USE, $stackPointer)) {
            $position = $phpCsFile->findPrevious(T_USE, $stackPointer);
            while ($position !== false) {
                $position = $phpCsFile->findPrevious(T_USE, $position);
                if ($position !== false) {
                    $end = $phpCsFile->findEndOfStatement($position);
                    if ($tokens[$position]['type'] === 'T_USE') {
                        $useTokens = array_slice($tokens, $position + 2, $end - $position - 2);
                        $useStatements[] = $this->parseUseParts($useTokens);
                    }
                }
                $position--;
            }
        }

        return $useStatements;
    }
499138
protected function getReturnTypes(File $phpCsFile, int $stackPointer): array
    {
        $tokens = $phpCsFile->getTokens();

        // We skip for interface methods
        if (empty($tokens[$stackPointer]['scope_opener']) || empty($tokens[$stackPointer]['scope_closer'])) {
            return [];
        }

        $scopeOpener = $tokens[$stackPointer]['scope_opener'];
        $scopeCloser = $tokens[$stackPointer]['scope_closer'];

        $returnTypes = [];
        for ($i = $scopeOpener; $i < $scopeCloser; $i++) {
            if ($tokens[$i]['code'] !== T_RETURN) {
                continue;
            }

            if (in_array(T_CLOSURE, $tokens[$i]['conditions'])) {
                continue;
            }

            $contentIndex = $phpCsFile->findNext(Tokens::$emptyTokens, $i + 1, $scopeCloser, true);
            if (!$contentIndex) {
                continue;
            }

            if ($tokens[$contentIndex]['code'] === T_PARENT) {
                $parentMethodName = $tokens[$contentIndex + 2]['content'];

                if ($parentMethodName === FunctionHelper::getName($phpCsFile, $stackPointer)) {
                    continue;
                }
            }

            $returnTypes[] = $tokens[$contentIndex]['content'];
        }

        return array_unique($returnTypes);
    }
180507
protected function updateAndGetCacheFileName($classFile)
    {
        $className = $this->className($classFile);

        if($this->hasChanged($classFile)){
            $content = $this->processClass($classFile);
            $this->writeCache($className, $content);
            $this->setDateFromClassFile($classFile);
        }

        return $this->cacheFile($className);
    }
212974
public static function all()
    {
        $command = 'grep --include="*.php" --files-with-matches -r "class" '.app_path();

        exec($command, $files);

        return collect($files)->map(function($file) {
            return self::convertFileToClass($file);
        })->filter(function($class) {
            return class_exists($class) && is_subclass_of($class, Model::class);
        });
    }
629088
private function _getDomainObjectsFromFile($file)
    {
        $result = array();

        if (fnmatch("*.php", $file)) {
            foreach ($this->_getClassFiles($file) as $namespace=>$classes) {
                foreach ($classes as $class) {
                    $fullClass = empty($namespace) ? "\\$class" : "\\$namespace\\$class";

                    $reflection = new \ReflectionClass($fullClass);
                    if (is_a($fullClass, "\Pheasant\DomainObject", true) && $reflection->isInstantiable()) {
                        $result []= $fullClass;
                    }
                }
            }
        }

        return $result;
    }
183399
public function findFile(string $class)
    {
        // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
        if ('\\' === $class[0]) {
            $class = (string)\substr($class, 1);
        }

        // class map lookup
        if (isset($this->classMap[$class])) {
            return $this->classMap[$class];
        }

        $file = $this->findFileWithExtension($class, '.php');

        if (false === $file) {
            // Remember that this class does not exist.
            $this->missingClasses[$class] = true;
        }

        return $file;
    }
677317
public static function getClassAndAlias($class)
    {
        if (false !== strpos($class, ' ')) {
            list($class, $alias) = explode(' ', $class);
        } else {
            $alias = null;
        }
        if (0 === strpos($class, '\\')) {
            $class = substr($class, 1);
        }

        return [$class, $alias];
    }
1207285
protected function hasChanged($classFile)
    {
        $className = $this->className($classFile);
        $cacheFile = $this->cacheFile($className);
        $cacheDate = file_exists($cacheFile) ? filemtime($cacheFile) : 0;
        $fileDate  = filemtime($classFile);

        return ($fileDate != $cacheDate);
    }