In this shorter part of the series, we'll start to build up an API for our analyser's rules. The idea here is that we want to be able to store as much information as we'd like on the rule itself, but still have a consistent API for executing the rule.

pub trait Rule: Debug { fn should_run(&self, node: &dyn Node) -> bool; fn run(&mut self, node: &dyn Node, definitions: &DefinitionCollection); }

impl Analyser { pub fn new() -> Self { Self { rules: Vec::new(), }} pub fn add_rule(&mut self, rule: Box ) { self.rules.push(rule); }}

pub fn run(args: AnalyseCommand) { let files = discoverer::discover(&["php"], &["."]).unwrap(); let mut collector = DefinitionCollector::new(); for file in files { let contents = std::fs::read(&file).unwrap(); let mut ast = pxp_parser::parse(&contents).unwrap(); collector.scan(&mut ast); } let collection = collector.collect(); let mut analyser = Analyser::new(collection); let contents = read(&args.file).unwrap(); let messages = analyser.analyse(args.file, &contents); dbg!(messages); }
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners