Search documentation of Metastatic

# Metastatic.Analysis.Complexity.FunctionMetrics (Metastatic v0.13.2)

View Source

Function-level complexity metrics.

Note: MetaAST currently doesn't have a function_definition construct. For Phase 4, we analyze the entire document as a single "function".

Future enhancement: Add function_definition to MetaAST M2.2 Extended layer for per-function analysis.

## Metrics

- Statement count: Number of executable statements
- Return points: Number of early_return nodes
- Variable count: Number of distinct variables used
- Parameter count: 0 (not applicable without function_definition)

## Examples

    iex> ast = {:assignment, [], [{:variable, [], "x"}, {:literal, [subtype: :integer], 5}]}
    iex> metrics = Metastatic.Analysis.Complexity.FunctionMetrics.calculate(ast)
    iex> metrics.statement_count
    1
    iex> metrics.variable_count
    1

## Summary

### Types

t()

### Functions

calculate(ast)

Calculates function-level metrics for a MetaAST node.

## Types

# t()

    @type t() :: %{
      statement_count: non_neg_integer(),
      return_points: non_neg_integer(),
      variable_count: non_neg_integer(),
      parameter_count: non_neg_integer()
    }

## Functions

# calculate(ast)

    @spec calculate(Metastatic.AST.meta_ast()) :: t()

Calculates function-level metrics for a MetaAST node.

## Examples

    iex> ast = {:early_return, [], [{:variable, [], "x"}]}
    iex> metrics = Metastatic.Analysis.Complexity.FunctionMetrics.calculate(ast)
    iex> metrics.return_points
    1