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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners