Search documentation of Metastatic

# Metastatic.Analysis.Smells.Result (Metastatic v0.2.0)

View Source

Result structure for code smell detection.

Contains information about detected code smells, their severity, and refactoring suggestions.

## Fields

- `:has_smells?` - Boolean indicating if any code smells were found
- `:smells` - List of detected smell details
- `:summary` - Human-readable summary of findings
- `:total_smells` - Count of detected smells
- `:by_severity` - Map of counts by severity
- `:by_type` - Map of counts by smell type

## Smell Types

- `:long_function` - Function with too many statements
- `:deep_nesting` - Excessive nesting depth
- `:magic_number` - Unexplained numeric literals
- `:complex_conditional` - Complex boolean expressions
- `:long_parameter_list` - Too many parameters
- `:duplicate_code` - Duplicated logic

## Examples

    iex> result = Metastatic.Analysis.Smells.Result.new([])
    iex> result.has_smells?
    false

    iex> smells = [%{type: :long_function, severity: :high, description: "test"}]
    iex> result = Metastatic.Analysis.Smells.Result.new(smells)
    iex> result.has_smells?
    true
    iex> result.total_smells
    1

# Summary

## Types

severity()
smell()
smell_type()
t()

## Functions

new(smells)

Creates a new result from a list of code smells.

no_smells()

Creates a result with no code smells.

to_map(result)

Converts result to JSON-compatible map.

# Types

# severity()

    @type severity() :: :critical | :high | :medium | :low

# smell()

    @type smell() :: %{
      type: smell_type(),
      severity: severity(),
      description: String.t(),
      suggestion: String.t(),
      context: term()
    }

# smell_type()

    @type smell_type() ::
      :long_function
      | :deep_nesting
      | :magic_number
      | :complex_conditional
      | :long_parameter_list
      | :duplicate_code

# t()

    @type t() :: %Metastatic.Analysis.Smells.Result{
      by_severity: %{required(severity()) => non_neg_integer()},
      by_type: %{required(smell_type()) => non_neg_integer()},
      has_smells?: boolean(),
      smells: [smell()],
      summary: String.t(),
      total_smells: non_neg_integer()
    }

# Functions

# new(smells)

    @spec new([smell()]) :: t()

Creates a new result from a list of code smells.

## Examples

    iex> Metastatic.Analysis.Smells.Result.new([])
    %Metastatic.Analysis.Smells.Result{has_smells?: false, summary: "No code smells detected"}

    iex> smells = [%{type: :long_function, severity: :high, description: "test", suggestion: "refactor", context: nil}]
    iex> result = Metastatic.Analysis.Smells.Result.new(smells)
    iex> result.has_smells?
    true

# no_smells()

    @spec no_smells() :: t()

Creates a result with no code smells.

## Examples

    iex> result = Metastatic.Analysis.Smells.Result.no_smells()
    iex> result.has_smells?
    false

# to_map(result)

    @spec to_map(t()) :: map()

Converts result to JSON-compatible map.

## Examples

    iex> result = Metastatic.Analysis.Smells.Result.new([])
    iex> map = Metastatic.Analysis.Smells.Result.to_map(result)
    iex> is_map(map)
    true