2) { continue; } $filtered_input_paths[] = $input_path; } if ($filtered_input_paths === ['-']) { $meta = stream_get_meta_data(STDIN); stream_set_blocking(STDIN, false); if ($stdin = fgets(STDIN)) { $filtered_input_paths = preg_split('/\s+/', trim($stdin)); } /** @var bool */ $blocked = $meta['blocked']; stream_set_blocking(STDIN, $blocked); } foreach ($filtered_input_paths as $path_to_check) { if ($path_to_check[0] === '-') { echo 'Invalid usage, expecting psalm [options] [file...]' . PHP_EOL; exit(1); } if (!file_exists($path_to_check)) { echo 'Cannot locate ' . $path_to_check . PHP_EOL; exit(1); } $path_to_check = realpath($path_to_check); if (!$path_to_check) { echo 'Error getting realpath for file' . PHP_EOL; exit(1); } $paths_to_check[] = $path_to_check; } if (!$paths_to_check) { $paths_to_check = null; } } return $paths_to_check; } /** * @param string $path * * @return bool */ function isAbsolutePath($path) { // Optional wrapper(s). $regex = '%^(?(?:[[:print:]]{2,}://)*)'; // Optional root prefix. $regex .= '(?(?:[[:alpha:]]:/|/)?)'; // Actual path. $regex .= '(?(?:[[:print:]]*))$%'; $parts = []; if (!preg_match($regex, $path, $parts)) { throw new InvalidArgumentException(sprintf('Path is not valid, "%s" given.', $path)); } if ('' !== $parts['root']) { return true; } return false; }