projectPath() public static method

public static projectPath ( string $relative_path ) : string
$relative_path string
return string The relative path appended to the project root directory.
Exemplo n.º 1
0
Arquivo: CLI.php Projeto: etsy/phan
 /**
  * @param string $directory_name
  * The name of a directory to scan for files ending in `.php`.
  *
  * @return string[]
  * A list of PHP files in the given directory
  */
 private function directoryNameToFileList(string $directory_name) : array
 {
     $file_list = [];
     try {
         $iterator = new \RegexIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory_name, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)), '/^.+\\.php$/i', \RecursiveRegexIterator::GET_MATCH);
         foreach (array_keys(iterator_to_array($iterator)) as $file_name) {
             $file_path = Config::projectPath($file_name);
             if (is_file($file_path) && is_readable($file_path)) {
                 $file_list[] = $file_name;
             } else {
                 error_log("Unable to read file {$file_path}");
             }
         }
     } catch (\Exception $exception) {
         error_log($exception->getMessage());
     }
     return $file_list;
 }
Exemplo n.º 2
0
 /**
  * Once we know what the universe looks like we
  * can scan for more complicated issues.
  *
  * @param CodeBase $code_base
  * The global code base holding all state
  *
  * @param string $file_path
  * A list of files to scan
  *
  * @return Context
  */
 public static function analyzeFile(CodeBase $code_base, string $file_path) : Context
 {
     // Set the file on the context
     $context = (new Context())->withFile($file_path);
     // Convert the file to an Abstract Syntax Tree
     // before passing it on to the recursive version
     // of this method
     try {
         $node = \ast\parse_file(Config::projectPath($file_path), Config::get()->ast_version);
     } catch (\ParseError $parse_error) {
         Issue::maybeEmit($code_base, $context, Issue::SyntaxError, $parse_error->getLine(), $parse_error->getMessage());
         return $context;
     }
     // Ensure we have some content
     if (empty($node)) {
         Issue::maybeEmit($code_base, $context, Issue::EmptyFile, 0, $file_path);
         return $context;
     }
     return (new BlockAnalysisVisitor($code_base, $context))($node);
 }
Exemplo n.º 3
0
Arquivo: CLI.php Projeto: etsy/phan
 /**
  * @param string $directory_name
  * The name of a directory to scan for files ending in `.php`.
  *
  * @return string[]
  * A list of PHP files in the given directory
  */
 private function directoryNameToFileList(string $directory_name) : array
 {
     $file_list = [];
     try {
         $file_extensions = Config::get()->analyzed_file_extensions;
         if (!is_array($file_extensions) || count($file_extensions) == 0) {
             throw new \InvalidArgumentException('Empty list in config analyzed_file_extensions. Nothing to analyze.');
         }
         $extension_regex = implode('|', array_map(function ($extension) {
             return preg_quote($extension, '/');
         }, $file_extensions));
         $iterator = new \RegexIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory_name, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)), '/^.+\\.(' . $extension_regex . ')$/i', \RecursiveRegexIterator::GET_MATCH);
         foreach (array_keys(iterator_to_array($iterator)) as $file_name) {
             $file_path = Config::projectPath($file_name);
             if (is_file($file_path) && is_readable($file_path)) {
                 $file_list[] = $file_name;
             } else {
                 error_log("Unable to read file {$file_path}");
             }
         }
     } catch (\Exception $exception) {
         error_log($exception->getMessage());
     }
     return $file_list;
 }