Skip to main content

Crate mir_plugin

Crate mir_plugin 

Source
Expand description

Plugin API for the mir PHP static analyzer, modeled on Psalm’s plugin event handlers (https://psalm.dev/docs/running_psalm/plugins/plugins_overview/).

A plugin implements MirPlugin, declares which hooks it wants via MirPlugin::hooks, and is registered into a PluginRegistry that the host process installs globally with install. The analyzer snapshots the registry once per analysis pass; when no registry is installed every hook site reduces to a single Option check.

Plugins come in two flavors:

  • Rust plugins — compiled in (registered directly) or loaded from a cdylib at runtime (dylib feature, see [dylib]).
  • Psalm PHP plugins — reused through a PHP host subprocess (psalm-bridge feature, see [psalm]).

Re-exports§

pub use mir_types;
pub use php_ast;

Macros§

export_plugin
Export a plugin constructor from a cdylib crate:

Structs§

AfterClassLikeAnalysisEvent
Counterpart of Psalm’s AfterClassLikeAnalysisEvent, fired once per class, interface, trait and enum declared in an analyzed file during batch runs.
AfterCodebasePopulatedEvent
Counterpart of Psalm’s AfterCodebasePopulatedEvent. Fired once per batch run after definition collection, before body analysis.
AfterExpressionAnalysisEvent
Counterpart of Psalm’s AfterExpressionAnalysisEvent.
AfterFunctionCallAnalysisEvent
Counterpart of Psalm’s AfterFunctionCallAnalysisEvent. return_type starts as the analyzer’s inferred type and may be replaced.
AfterFunctionLikeAnalysisEvent
Counterpart of Psalm’s AfterFunctionLikeAnalysisEvent, for named functions and methods.
AfterMethodCallAnalysisEvent
Counterpart of Psalm’s AfterMethodCallAnalysisEvent.
AfterStatementAnalysisEvent
Counterpart of Psalm’s AfterStatementAnalysisEvent.
ArrayPropertyDefault
An array-literal property default declared on a class, exposed to ClassPropertyProviderEvent so a plugin can interpret framework conventions like Eloquent’s protected $casts = [...] without re-parsing.
AttributeArgInfo
A parameter attribute argument, as far as mir can evaluate it statically.
AttributeInfo
ClassPropertyProviderEvent
Counterpart of Psalm’s PropertiesProviderInterface: supply the type of a property that is not declared on the class (nor reachable via @property), e.g. an Eloquent attribute synthesized from $casts. Dispatched when a property access misses on a class whose own FQCN or an ancestor is listed in MirPlugin::class_property_classes.
FunctionLikeParamInfo
FunctionReturnTypeProviderEvent
Counterpart of Psalm’s FunctionReturnTypeProviderEvent.
HookFlags
Which event hooks a plugin subscribes to. Sites only construct events and dispatch when at least one registered plugin set the matching flag, so an unset flag keeps that hook zero-cost.
Issue
MethodReturnTypeProviderEvent
Counterpart of Psalm’s MethodReturnTypeProviderEvent.
PluginDeclaration
Entry-point record a Rust cdylib plugin exports under the symbol MIR_PLUGIN_DECLARATION. Use export_plugin! instead of writing this by hand.
PluginIssue
An issue raised by a plugin. Converted by the analyzer into IssueKind::PluginIssue with a proper source Location.
PluginRegistry
Type

Enums§

ProvidedType
A type contributed by a plugin. Parse carries a docblock-syntax type string (e.g. list<non-empty-string>) that the analyzer resolves with its own type parser in the context of the analyzed file — this is what the Psalm bridge returns, since PHP-side plugins produce type strings.
Severity

Constants§

MIR_PLUGIN_API_VERSION
Bumped whenever the MirPlugin trait or event types change incompatibly. Dylib plugins built against a different version are refused at load time.

Traits§

MirPlugin
A mir plugin. Hook methods take &self and may run concurrently from rayon workers — use interior mutability with proper synchronization.

Functions§

install
Install the process-wide plugin registry. The analyzer takes an Arc snapshot per pass, so re-installing affects subsequent passes only.
normalize_id
Normalize a function id or FQCN for provider-map lookup: lowercase, no leading backslash.
snapshot
Snapshot the installed registry. None when no plugins are loaded — the common case, which every hook site checks first.