MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / run

Function run

src/fix.rs:199–476  ·  view source on GitHub ↗

Run the fix command and return the process exit code. Returns `0` when fixes were applied (or nothing to fix), `1` on error, `2` when `--dry-run` found fixable issues.

(options: FixOptions)

Source from the content-addressed store, hash-verified

197/// Returns `0` when fixes were applied (or nothing to fix), `1` on error,
198/// `2` when `--dry-run` found fixable issues.
199pub async fn run(options: FixOptions) -> i32 {
200 let root = &options.workspace_root;
201
202 if !root.join("composer.json").is_file() {
203 eprintln!("Error: no composer.json found in {}", root.display());
204 eprintln!("The fix command currently only supports single Composer projects.");
205 return 1;
206 }
207
208 // ── Validate rules ──────────────────────────────────────────────
209 let rule_errors = validate_rules(&options.rules, options.with_phpstan);
210 if !rule_errors.is_empty() {
211 for err in &rule_errors {
212 eprintln!("Error: {err}");
213 }
214 return 1;
215 }
216
217 let native_rules = effective_native_rules(&options.rules);
218 if native_rules.is_empty() && !options.with_phpstan {
219 eprintln!("No applicable rules to run.");
220 return 0;
221 }
222
223 // ── 1. Load config ──────────────────────────────────────────────
224 let cfg = match config::load_config(root) {
225 Ok(c) => c,
226 Err(e) => {
227 eprintln!("Warning: failed to load .phpantom.toml: {e}");
228 config::Config::default()
229 }
230 };
231
232 // ── 2. Index project ────────────────────────────────────────────
233 let backend = Backend::new_headless();
234 *backend.workspace_root().write() = Some(root.to_path_buf());
235 *backend.config.lock() = cfg.clone();
236
237 let composer_package = composer::read_composer_package(root);
238
239 let php_version = cfg
240 .php
241 .version
242 .as_deref()
243 .and_then(crate::types::PhpVersion::from_composer_constraint)
244 .unwrap_or_else(|| {
245 composer_package
246 .as_ref()
247 .and_then(composer::detect_php_version_from_package)
248 .unwrap_or_default()
249 });
250 backend.set_php_version(php_version);
251
252 backend
253 .init_single_project(root, php_version, composer_package, None)
254 .await;
255
256 // ── 3. Discover files ───────────────────────────────────────────

Callers 1

mainFunction · 0.70

Calls 15

validate_rulesFunction · 0.85
effective_native_rulesFunction · 0.85
load_configFunction · 0.85
read_composer_packageFunction · 0.85
discover_user_filesFunction · 0.85
path_to_uriFunction · 0.85
with_parse_cacheFunction · 0.85
print_fix_jsonFunction · 0.85
print_fix_tableFunction · 0.85
print_dry_run_boxFunction · 0.85

Tested by

no test coverage detected