# Complexity Analyzer

> Analyzes cyclomatic and cognitive complexity, identifies overly complex functions. Use when assessing code complexity or identifying functions that need simplification.

- **Type:** Skill
- **Install:** `agentstack add skill-armanzeroeight-fastagent-plugins-complexity-analyzer`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [armanzeroeight](https://agentstack.voostack.com/s/armanzeroeight)
- **Installs:** 0
- **Category:** [Cloud & Infrastructure](https://agentstack.voostack.com/c/cloud-infrastructure)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [armanzeroeight](https://github.com/armanzeroeight)
- **Source:** https://github.com/armanzeroeight/fastagent-plugins/tree/main/plugins/code-quality-toolkit/skills/complexity-analyzer

## Install

```sh
agentstack add skill-armanzeroeight-fastagent-plugins-complexity-analyzer
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Complexity Analyzer

## Quick Start

Analyze complexity with tools:

```bash
# JavaScript
npx eslint --plugin complexity --rule 'complexity: [error, 10]' src/

# Python
pip install radon
radon cc src/ -a -nb

# General
npx complexity-report src/
```

## Instructions

### Step 1: Calculate Cyclomatic Complexity

Count decision points + 1:
- if, else, elif
- for, while loops
- case statements
- && and || operators
- ternary operators
- catch blocks

**Example:**
```javascript
function example(x) {  // +1 (base)
  if (x > 0) {         // +1
    return x;
  } else if (x 20)

**processOrder()** - src/orders.js:45
- Cyclomatic: 28
- Cognitive: 35
- Lines: 127
- Recommendation: Extract validation, calculation, and persistence logic

**validateUser()** - src/auth.js:12
- Cyclomatic: 22
- Cognitive: 28
- Lines: 89
- Recommendation: Extract individual validation rules

### Moderate Complexity (11-20)

[List functions with complexity 11-20]
```

## Simplification Strategies

### Extract Method
```javascript
// Before: Complexity 15
function processData(data) {
  if (data.type === 'A') {
    // 20 lines of processing
  } else if (data.type === 'B') {
    // 20 lines of processing
  }
}

// After: Complexity 3
function processData(data) {
  if (data.type === 'A') return processTypeA(data);
  if (data.type === 'B') return processTypeB(data);
}
```

### Replace Nested Conditionals
```javascript
// Before: Cognitive 12
function getPrice(user, product) {
  if (user) {
    if (user.isPremium) {
      if (product.onSale) {
        return product.price * 0.7;
      } else {
        return product.price * 0.9;
      }
    }
  }
  return product.price;
}

// After: Cognitive 4
function getPrice(user, product) {
  if (!user || !user.isPremium) return product.price;
  if (product.onSale) return product.price * 0.7;
  return product.price * 0.9;
}
```

### Use Polymorphism
```javascript
// Before: Complexity 8
function getArea(shape) {
  if (shape.type === 'circle') {
    return Math.PI * shape.radius ** 2;
  } else if (shape.type === 'square') {
    return shape.side ** 2;
  }
  // ... more types
}

// After: Complexity 1 per class
class Circle {
  getArea() { return Math.PI * this.radius ** 2; }
}
class Square {
  getArea() { return this.side ** 2; }
}
```

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [armanzeroeight](https://github.com/armanzeroeight)
- **Source:** [armanzeroeight/fastagent-plugins](https://github.com/armanzeroeight/fastagent-plugins)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-armanzeroeight-fastagent-plugins-complexity-analyzer
- Seller: https://agentstack.voostack.com/s/armanzeroeight
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
