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)); } $blocked = $meta['blocked']; stream_set_blocking(STDIN, $blocked); } foreach ($filtered_input_paths as $path_to_check) { if ($path_to_check[0] === '-') { fwrite(STDERR, 'Invalid usage, expecting psalm [options] [file...]' . PHP_EOL); exit(1); } if (!file_exists($path_to_check)) { fwrite(STDERR, 'Cannot locate ' . $path_to_check . PHP_EOL); exit(1); } $path_to_check = realpath($path_to_check); if (!$path_to_check) { fwrite(STDERR, '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; } function getPsalmHelpText(): string { return <<getMessage() . PHP_EOL); exit(1); } $config->setComposerClassLoader($first_autoloader); return $config; } function update_config_file(Config $config, string $config_file_path, string $baseline_path) : void { if ($config->error_baseline === $baseline_path) { return; } $configFile = Config::locateConfigFile($config_file_path); if (!$configFile) { fwrite(STDERR, "Don't forget to set errorBaseline=\"{$baseline_path}\" to your config."); return; } $configFileContents = file_get_contents($configFile); if ($config->error_baseline) { $amendedConfigFileContents = preg_replace( '/errorBaseline=".*?"/', "errorBaseline=\"{$baseline_path}\"", $configFileContents ); } else { $endPsalmOpenTag = strpos($configFileContents, '>', (int)strpos($configFileContents, '", $endPsalmOpenTag, 1 ); } else { $amendedConfigFileContents = substr_replace( $configFileContents, " errorBaseline=\"{$baseline_path}\">", $endPsalmOpenTag, 1 ); } } file_put_contents($configFile, $amendedConfigFileContents); } function get_path_to_config(array $options): ?string { $path_to_config = isset($options['c']) && is_string($options['c']) ? realpath($options['c']) : null; if ($path_to_config === false) { fwrite(STDERR, 'Could not resolve path to config ' . (string) ($options['c'] ?? '') . PHP_EOL); exit(1); } return $path_to_config; } function getMemoryLimitInBytes(): int { $limit = ini_get('memory_limit'); // for unlimited = -1 if ($limit < 0) { return -1; } if (preg_match('/^(\d+)(\D?)$/', $limit, $matches)) { $limit = (int)$matches[1]; switch (strtoupper($matches[2] ?? '')) { case 'G': $limit *= 1024 * 1024 * 1024; break; case 'M': $limit *= 1024 * 1024; break; case 'K': $limit *= 1024; break; } } return (int)$limit; }