Metastatic.Analysis.ApiSurface (Metastatic v0.10.4)

View Source

API surface analysis for containers (modules/classes).

Analyzes the public interface, measuring complexity, consistency, and design quality.

Metrics

  • Surface Size: Number of public methods/properties
  • Parameter Complexity: Average parameters per public method
  • Return Complexity: Variety of return types
  • Naming Consistency: Consistent naming patterns
  • Interface Cohesion: How focused the API is

Examples

# Small, focused API
ast = {:container, :class, "Stack", %{}, [
  {:function_def, :public, "push", ["item"], %{}, ...},
  {:function_def, :public, "pop", [], %{}, ...}
]}

doc = Document.new(ast, :python)
{:ok, result} = ApiSurface.analyze(doc)
result.surface_size  # => 2
result.assessment    # => :excellent

Summary

Functions

Analyzes a document for Metastatic.Analysis.ApiSurface, raising on error.

Analyzes a document for Metastatic.Analysis.ApiSurface, raising on error.

Types

result()

@type result() :: %{
  container_name: String.t() | nil,
  surface_size: non_neg_integer(),
  public_methods: [String.t()],
  avg_params: float(),
  max_params: non_neg_integer(),
  assessment: :excellent | :good | :fair | :poor,
  warnings: [String.t()],
  recommendations: [String.t()]
}

Functions

analyze(language_or_doc, source_or_ast_or_opts \\ [], opts \\ [])

@spec analyze(Metastatic.language(), term(), keyword()) ::
  {:ok, map()} | {:error, term()}

Analyzes a document for Metastatic.Analysis.ApiSurface, raising on error.

analyze!(language_or_doc, source_or_ast_or_opts \\ [], opts \\ [])

@spec analyze!(Metastatic.language(), term(), keyword()) :: map()

Analyzes a document for Metastatic.Analysis.ApiSurface, raising on error.

Unlike not-banged version, this one either returns a result or raises