Metastatic.Analysis.StateManagement.Result
(Metastatic v0.10.4)
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
Functions
Assess state management quality.
Generate recommendations based on pattern.
Generate warnings based on state management issues.
Identify state management pattern based on metrics.
Create a mutation record.
Types
@type assessment() :: :excellent | :good | :fair | :poor
@type pattern() ::
:stateless
| :immutable_state
| :controlled_mutation
| :uncontrolled_mutation
| :mixed
@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
@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
@spec generate_recommendations(pattern(), non_neg_integer()) :: [String.t()]
Generate recommendations based on pattern.
@spec generate_warnings(pattern(), non_neg_integer(), [String.t()]) :: [String.t()]
Generate warnings based on state management issues.
@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
Create a mutation record.