Search documentation of Metastatic

# Metastatic.Analysis.StateManagement.Result (Metastatic v0.13.2)

View Source

Result structure for state management analysis.

Analyzes how containers manage state, identifying patterns like:

- Stateful vs stateless design
- Mutation patterns
- State initialization
- State consistency

## State Patterns

- Stateless: Container has no mutable state
- Immutable State: State exists but is never modified after initialization
- Controlled Mutation: State modified through well-defined methods
- Uncontrolled Mutation: State modified directly without validation

## Examples

    iex> result = %Metastatic.Analysis.StateManagement.Result{
    ...>   container_name: "Calculator",
    ...>   pattern: :stateless,
    ...>   state_count: 0,
    ...>   mutation_count: 0
    ...> }
    iex> result.pattern
    :stateless

## Summary

### Types

assessment()
mutation()
pattern()
t()

### Functions

assess(pattern, mutation_count, warnings)

Assess state management quality.

generate_recommendations(pattern, state_count)

Generate recommendations based on pattern.

generate_warnings(pattern, mutation_count, uninitialized)

Generate warnings based on state management issues.

identify_pattern(state_count, mutation_count, read_only, mutable)

Identify state management pattern based on metrics.

mutation(location, state_var, operation, severity \\ :medium)

Create a mutation record.

## Types

# assessment()

    @type assessment() :: :excellent | :good | :fair | :poor

# mutation()

    @type mutation() :: %{
      location: String.t(),
      state_var: String.t(),
      operation: :assignment | :augmented_assignment | :increment | :decrement,
      severity: :low | :medium | :high
    }

# pattern()

    @type pattern() ::
      :stateless
      | :immutable_state
      | :controlled_mutation
      | :uncontrolled_mutation
      | :mixed

# t()

    @type t() :: %Metastatic.Analysis.StateManagement.Result{
      assessment: assessment(),
      container_name: String.t() | nil,
      container_type: :module | :class | :namespace | nil,
      initialized_state: [String.t()],
      mutable_state: [String.t()],
      mutation_count: non_neg_integer(),
      mutations: [mutation()],
      pattern: pattern(),
      read_only_state: [String.t()],
      recommendations: [String.t()],
      state_count: non_neg_integer(),
      uninitialized_state: [String.t()],
      warnings: [String.t()]
    }

## Functions

# assess(pattern, mutation_count, warnings)

    @spec assess(pattern(), non_neg_integer(), [String.t()]) :: assessment()

Assess state management quality.

## Examples

    iex> Metastatic.Analysis.StateManagement.Result.assess(:stateless, 0, [])
    :excellent

    iex> Metastatic.Analysis.StateManagement.Result.assess(:controlled_mutation, 5, [])
    :good

    iex> Metastatic.Analysis.StateManagement.Result.assess(:uncontrolled_mutation, 20, ["warning"])
    :poor

# generate_recommendations(pattern, state_count)

    @spec generate_recommendations(pattern(), non_neg_integer()) :: [String.t()]

Generate recommendations based on pattern.

# generate_warnings(pattern, mutation_count, uninitialized)

    @spec generate_warnings(pattern(), non_neg_integer(), [String.t()]) :: [String.t()]

Generate warnings based on state management issues.

# identify_pattern(state_count, mutation_count, read_only, mutable)

    @spec identify_pattern(non_neg_integer(), non_neg_integer(), [String.t()], [
      String.t()
    ]) :: pattern()

Identify state management pattern based on metrics.

## Examples

    iex> Metastatic.Analysis.StateManagement.Result.identify_pattern(0, 0, [], [])
    :stateless

    iex> Metastatic.Analysis.StateManagement.Result.identify_pattern(2, 0, ["x", "y"], [])
    :immutable_state

    iex> Metastatic.Analysis.StateManagement.Result.identify_pattern(3, 5, ["x"], ["y", "z"])
    :controlled_mutation

# mutation(location, state_var, operation, severity \\ :medium)

    @spec mutation(String.t(), String.t(), atom(), atom()) :: mutation()

Create a mutation record.