Skip to main content

mir_php/
lib.rs

1//! `mir-php` — PHP static analysis engine.
2//!
3//! Provides type inference and semantic diagnostics for PHP source code,
4//! operating directly on [`php_ast`] AST slices with no dependency on any
5//! LSP framework.
6//!
7//! # Usage
8//!
9//! ```ignore
10//! use bumpalo::Bump;
11//! use php_rs_parser::parse;
12//!
13//! let arena = Bump::new();
14//! let program = parse(source, &arena).unwrap();
15//!
16//! let diags = mir_php::analyze(source, &program.stmts, &[]);
17//! let env   = mir_php::infer(&program.stmts);
18//! ```
19
20pub mod diag;
21pub mod infer;
22pub mod stubs;
23pub mod types;
24pub mod util;
25
26pub use diag::{Diagnostic, Severity};
27pub use types::{Ty, TypeEnv};
28
29/// Analyse `stmts` against `all` workspace documents and return diagnostics.
30///
31/// - `source` — the raw PHP source text for `stmts` (used for position mapping)
32/// - `stmts`  — AST of the document being checked
33/// - `all`    — every document in the workspace as `(source, stmts)` pairs;
34///              include the current document so its definitions are visible
35pub fn analyze<'a>(
36    source: &str,
37    stmts: &[php_ast::Stmt<'a, 'a>],
38    all: &[(&str, &[php_ast::Stmt<'a, 'a>])],
39) -> Vec<Diagnostic> {
40    diag::analyze(source, stmts, all)
41}
42
43/// Build a `TypeEnv` (variable → type map) from `stmts`.
44pub fn infer<'a>(stmts: &[php_ast::Stmt<'a, 'a>]) -> TypeEnv {
45    infer::infer(stmts)
46}