PHP SDK index

This page indexes the public extension authoring API. Public symbols live under Mago\Sdk and carry @api. Symbols under Mago\Sdk\Internal implement the bundled binary protocol and are not a compatibility surface.

Runtime

TypePurpose
ExtensionDeclares one logical extension's rules, plugins, version, and optional reducer
WorkerHosts one or more extensions in one command-scoped worker process
WorkerReducerExports and merges process-local state at pool shutdown
WorkerReductionContextOrdered worker payloads and cancellation for the surviving reducer
CancellationTokenInterfaceCooperative request cancellation
PHPVersionMago's configured target language version
SpanHalf-open byte range within a source file
SourceLocationLogical filename plus span

See Extensions and workers and Worker state and reduction.

Exceptions

SdkException is the common marker. InvalidArgumentException reports invalid public DTO construction, ProtocolException reports a worker/protocol contract failure, and CancelledException terminates cancelled callback work.

Syntax

TypePurpose
Syntax\SourceFileImmutable capability-specific source, syntax, names, optional literals, and optional comment trivia
Syntax\NodeOne concrete-syntax node
Syntax\NodeKindGenerated syntax-node enum used by protocol snapshots
Syntax\ResolvedNameResolved semantic name and source span
Syntax\Trivia, Syntax\TriviaKindComments and their lexical kind
Syntax\CallExpressionStructured function or method call view
Syntax\CallArgumentStructured call argument view

See Syntax nodes and source files.

Reporting

TypePurpose
Reporting\IssueImmutable extension diagnostic builder
Reporting\ReportedIssueRead-only issue with effective code and level
Reporting\Annotation, Reporting\AnnotationKindPrimary and secondary source annotations
Reporting\LevelNote, help, warning, or error severity
Reporting\TextEditDelete, insert, or replace suggestion
Reporting\SafetySafe, potentially unsafe, or unsafe edit classification

See Reporting issues and suggested edits.

Linter

TypePurpose
Linter\RuleCustom linter rule contract
Linter\RuleDefinitionCode, name, description, level, activation, and syntax targets
Linter\LintContextCurrent source, target node, traversal, names, cancellation, and reporting

See Writing linter rules.

Analyzer plugin registration

TypePurpose
Analyzer\PluginAnalyzer plugin contract
Analyzer\PluginDefinitionIdentifier, aliases, description, and default activation
Analyzer\PluginRegistryRegisters every provider, hook, entry point, filter, and memoization policy
Analyzer\TargetedProviderCommon non-empty target-list contract
Analyzer\TargetedAnalysisHookCommon targets, requirements, and post-analysis node callback

See Analyzer plugins.

Analyzer lifecycle

HookContext and data
InitializationHookInitializationContext: PHP version, cancellation, in-memory stubs
CodebaseScanHookCodebaseScanContext: deterministic batches of selected host source
BeforeAnalysisHookBeforeAnalysisContext: frozen codebase and project-wide reference registry
AfterFileAnalysisHookAfterFileAnalysisContext: completed FileAnalysis and file references
AfterAnalysisHookAfterAnalysisContext: merged ProjectAnalysis and final reference graph

LifecycleContext supplies PHP version, Codebase, TypeComparator, cancellation, and analyzer issue reporting. FileAnalysisRequirement::ExpressionTypes configures plain after-file hooks; the remaining cases configure targeted hooks.

See Lifecycle hooks.

Return types and call signatures

TypePurpose
FunctionReturnTypeProviderRefines selected function return types
MethodReturnTypeProviderRefines selected instance or static method return types
ReturnTypeProviderContextInvocation with inferred argument types and semantic services
CallableSignatureProviderEstablishes parameters for an unresolved callable
CallableSignatureOverrideMarks a signature provider that may replace a declaration
UndeclaredReturnTypeProviderMarks a return provider as unresolved-callable-only
CallableSignatureProviderContextPre-argument invocation and semantic services
EffectiveCallableSignatureParameters and named-argument policy used by Mago
Type\CallableParameterParameter name, type, closure $this, reference, variadic, and default facts
Invocation, InvocationKindFunction, instance-method, or static-method call
ArgumentNamed/positional source argument and optional inferred type

Targets are FunctionTarget with FunctionTargetKind, or MethodTarget. See Return types and callable signatures.

Assertions

FunctionAssertionProvider, MethodAssertionProvider, and AssertionProviderContext produce InvocationAssertions.

The assertion value families are:

  • Assertion\TypeAssertion and TypeAssertionKind;
  • Assertion\SimpleAssertion and SimpleAssertionKind;
  • Assertion\IntegerAssertion and IntegerAssertionKind;
  • Assertion\ArrayKeyAssertion and ArrayKeyAssertionKind;
  • Assertion\CountabilityAssertion and CountabilityAssertionKind;
  • Assertion\VariableAssertion and VariableAssertionKind.

All implement the Assertion\Assertion marker. See Assertion providers.

Properties and initialization

TypePurpose
PropertyTypeProvider, PropertyTypeProviderContextEstablish a dynamic property or override a selected property's access types
PropertyTypeOptional read and write contracts
PropertyAccess, PropertyAccessKindCurrent property, receiver, span, and read/write operation
PropertyInitializationProvider, PropertyInitializationProviderContextMark a selected declared property initialized
ClassInitializerProvider, ClassInitializerProviderContextDeclare lifecycle methods that initialize properties

Targets are PropertyTarget and ClassTarget. See Properties and initialization.

Targeted analysis

HookTarget
NodeAnalysisHookExact Syntax\NodeKind cases
MethodCallAnalysisHookResolved MethodTarget patterns
ClassLikeAnalysisHookClassLikeTarget descendant declarations

All receive NodeAnalysisContext. See Targeted analysis hooks.

Entry points and filters

AttributedEntryPoint, ClassTarget, and MethodTarget describe native framework entry points. IssueFilterHook, IssueFilterContext, and IssueFilterDecision implement targeted last-resort filtering. See Entry points and issue filtering.

Analysis results and references

TypePurpose
FileAnalysisCompleted per-file summary and lazy artifacts
ExpressionTypeExpression span plus inferred type
ProjectAnalysisFinal files, issue count, and merged references
ReferenceRegistryContributes framework-known edges
ReferenceOriginSymbol/member or file edge origin
ReferenceKindBody, signature, overridden-member, function-like-return, property-read, or property-write edge
ReferenceSummaryAggregate reference counts
SymbolReferencesLazy final graph queries
SymbolReferenceOne directed graph edge

See Analysis results and references.

Codebase metadata

Codebase queries immutable Mago metadata. Public metadata DTOs are:

  • Metadata\ClassLikeMetadata and ClassLikeKind;
  • Metadata\FunctionLikeMetadata and FunctionLikeKind;
  • Metadata\ParameterMetadata;
  • Metadata\PropertyMetadata and PropertyHookMetadata;
  • Metadata\ClassConstantMetadata, EnumCaseMetadata, and ConstantMetadata;
  • Metadata\TemplateMetadata and TypeMetadata;
  • Metadata\AttributeMetadata and AttributeArgumentMetadata;
  • Metadata\MemberIdentifier;
  • Metadata\MethodMetadataProjection and MethodFields;
  • Metadata\MetadataFlags and VersionRange.

See Codebase metadata.

Types

Analyzer\Type is an immutable union. TypeComparator, TypeComparison, and TypeComparisonKind delegate equality, containment, and overlap to Mago.

Atomic values implement Type\AtomicType:

  • AliasType, ReferenceType, and VariableType;
  • MixedType, SimpleAtomicType, ScalarType, and ResourceType;
  • AnyObjectType, NamedObjectType, and EnumType;
  • ObjectShapeType, ObjectWithMethodType, and ObjectWithPropertyType;
  • KeyedArrayType, ListType, and IterableType;
  • CallableType, GenericParameterType, ConditionalType, and DerivedType.

Supporting type values and enums are:

  • ArrayItem, ArrayKey, and ArrayKeyKind;
  • CallableConstraint, CallableParameter, and CallableSignature;
  • ClassLikeStringType, ClassLikeStringKind, and ClassLikeStringVariant;
  • FloatType, FloatTypeKind, IntegerType, and IntegerTypeKind;
  • ScalarTypeKind, SimpleAtomicTypeKind, and MixedTruthiness;
  • StringType, StringLiteralKind, and StringCasing;
  • FunctionLikeIdentifier and Type\FunctionLikeKind;
  • GenericParent, GenericParentKind, Variance, and Visibility;
  • ListElement, ObjectProperty, and TypeFlags;
  • DerivedTypeKind, ReferenceTypeKind, and ReferenceSelectorKind.

See Types and comparisons.

↳ Edit this page →