suggest-simplification

Suggests code simplification opportunities. Identifies extract method candidates, complex expressions, redundant code, refactoring opportunities.

59 stars

Best use case

suggest-simplification is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Suggests code simplification opportunities. Identifies extract method candidates, complex expressions, redundant code, refactoring opportunities.

Teams using suggest-simplification should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/suggest-simplification/SKILL.md --create-dirs "https://raw.githubusercontent.com/dykyi-roman/awesome-claude-code/main/skills/suggest-simplification/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/suggest-simplification/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How suggest-simplification Compares

Feature / Agentsuggest-simplificationStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Suggests code simplification opportunities. Identifies extract method candidates, complex expressions, redundant code, refactoring opportunities.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Code Simplification Suggestions

Analyze PHP code for simplification and refactoring opportunities.

## Simplification Patterns

### 1. Extract Method

```php
// BEFORE: Long inline code block
public function processOrder(Order $order): void
{
    // Validate order (5 lines)
    if ($order->getItems()->isEmpty()) {
        throw new EmptyOrderException();
    }
    if ($order->getTotal()->isNegative()) {
        throw new InvalidTotalException();
    }

    // Process payment (10 lines)
    $payment = $this->paymentGateway->charge(
        $order->getTotal(),
        $order->getPaymentMethod()
    );
    if (!$payment->isSuccessful()) {
        throw new PaymentFailedException();
    }

    // Send notifications (5 lines)
    $this->mailer->send($order->getCustomer()->getEmail(), 'order_confirmed');
}

// AFTER: Extracted methods
public function processOrder(Order $order): void
{
    $this->validateOrder($order);
    $this->processPayment($order);
    $this->sendConfirmation($order);
}

private function validateOrder(Order $order): void {}
private function processPayment(Order $order): Payment {}
private function sendConfirmation(Order $order): void {}
```

### 2. Introduce Explaining Variable

```php
// BEFORE: Complex expression
if ($user->getSubscription()?->isActive()
    && $user->getCreatedAt() < new DateTime('-30 days')
    && !$user->hasUsedTrial()
    && $user->getOrderCount() > 0) {
    $this->offerUpgrade($user);
}

// AFTER: Named variables
$hasActiveSubscription = $user->getSubscription()?->isActive();
$isEstablishedUser = $user->getCreatedAt() < new DateTime('-30 days');
$eligibleForUpgrade = !$user->hasUsedTrial() && $user->getOrderCount() > 0;

if ($hasActiveSubscription && $isEstablishedUser && $eligibleForUpgrade) {
    $this->offerUpgrade($user);
}

// EVEN BETTER: Extract to method
if ($user->isEligibleForUpgrade()) {
    $this->offerUpgrade($user);
}
```

### 3. Remove Redundant Code

```php
// BEFORE: Redundant checks
if ($value !== null) {
    if ($value !== null) {  // Duplicate check
        $this->process($value);
    }
}

// BEFORE: Unnecessary else
if ($condition) {
    return $a;
} else {
    return $b;
}

// AFTER: Simplified
if ($condition) {
    return $a;
}
return $b;

// BEFORE: Redundant boolean
if ($condition === true) {}
return $value === true;

// AFTER: Simplified
if ($condition) {}
return $value;
```

### 4. Simplify Conditionals

```php
// BEFORE: Nested conditionals
if ($user !== null) {
    if ($user->isActive()) {
        if ($user->hasPermission('edit')) {
            return true;
        }
    }
}
return false;

// AFTER: Combined condition
return $user !== null
    && $user->isActive()
    && $user->hasPermission('edit');

// BEFORE: Negative condition
if (!$items->isEmpty()) {
    $this->process($items);
}

// AFTER: Positive condition
if ($items->isNotEmpty()) {
    $this->process($items);
}
```

### 5. Replace Temp with Query

```php
// BEFORE: Temporary variable used once
$basePrice = $order->getBasePrice();
$discount = $basePrice * 0.1;
return $basePrice - $discount;

// AFTER: Inline or method
return $order->getBasePrice() * 0.9;

// Or if complex:
return $order->getBasePrice() - $this->calculateDiscount($order);
```

### 6. Use Collection Methods

```php
// BEFORE: Manual loop
$active = [];
foreach ($users as $user) {
    if ($user->isActive()) {
        $active[] = $user;
    }
}

// AFTER: array_filter
$active = array_filter($users, fn($user) => $user->isActive());

// BEFORE: Manual map
$emails = [];
foreach ($users as $user) {
    $emails[] = $user->getEmail();
}

// AFTER: array_map
$emails = array_map(fn($user) => $user->getEmail(), $users);

// BEFORE: Manual find
$found = null;
foreach ($items as $item) {
    if ($item->getId() === $id) {
        $found = $item;
        break;
    }
}

// AFTER: Collection method
$found = $collection->first(fn($item) => $item->getId() === $id);
```

### 7. Replace Switch with Polymorphism

```php
// BEFORE: Switch on type
public function calculateShipping(Order $order): Money
{
    switch ($order->getShippingMethod()) {
        case 'standard':
            return $this->calculateStandardShipping($order);
        case 'express':
            return $this->calculateExpressShipping($order);
        case 'overnight':
            return $this->calculateOvernightShipping($order);
        default:
            throw new InvalidMethodException();
    }
}

// AFTER: Strategy pattern
interface ShippingCalculator {
    public function calculate(Order $order): Money;
}

class StandardShipping implements ShippingCalculator {}
class ExpressShipping implements ShippingCalculator {}

public function calculateShipping(Order $order): Money
{
    return $this->shippingCalculators
        ->get($order->getShippingMethod())
        ->calculate($order);
}
```

### 8. Null Object Pattern

```php
// BEFORE: Null checks everywhere
if ($user->getAddress() !== null) {
    echo $user->getAddress()->getCity();
} else {
    echo 'Unknown';
}

// AFTER: Null Object
class NullAddress implements AddressInterface
{
    public function getCity(): string
    {
        return 'Unknown';
    }
}

// Always safe to call
echo $user->getAddress()->getCity();
```

### 9. Guard Clauses

```php
// BEFORE: Deeply nested
public function process(Request $request): Response
{
    if ($request !== null) {
        if ($request->isValid()) {
            if ($this->canProcess($request)) {
                return $this->doProcess($request);
            } else {
                return $this->error('Cannot process');
            }
        } else {
            return $this->error('Invalid request');
        }
    } else {
        return $this->error('No request');
    }
}

// AFTER: Guard clauses
public function process(Request $request): Response
{
    if ($request === null) {
        return $this->error('No request');
    }

    if (!$request->isValid()) {
        return $this->error('Invalid request');
    }

    if (!$this->canProcess($request)) {
        return $this->error('Cannot process');
    }

    return $this->doProcess($request);
}
```

### 10. Use Modern PHP Features

```php
// BEFORE: Old syntax
$name = isset($data['name']) ? $data['name'] : 'default';

// AFTER: Null coalescing
$name = $data['name'] ?? 'default';

// BEFORE: Property assignment
$value = $object->getValue();
if ($value !== null) {
    echo $value;
}

// AFTER: Nullsafe operator
echo $object?->getValue();

// BEFORE: Match as if/else
if ($status === 'active') {
    $color = 'green';
} elseif ($status === 'pending') {
    $color = 'yellow';
} else {
    $color = 'red';
}

// AFTER: Match expression
$color = match($status) {
    'active' => 'green',
    'pending' => 'yellow',
    default => 'red',
};
```

## Severity Classification

| Pattern | Severity |
|---------|----------|
| Deeply nested code | 🟠 Major |
| Repeated code blocks | 🟠 Major |
| Complex boolean expressions | 🟡 Minor |
| Old syntax available in modern PHP | 🟢 Suggestion |
| Verbose but clear code | 🟢 Suggestion |

## Output Format

```markdown
### Simplification: [Description]

**Severity:** 🟠/🟡/🟢
**Location:** `file.php:line`
**Type:** [Extract Method|Guard Clause|Collection Method|...]

**Issue:**
[Description of the complexity]

**Current:**
```php
// Complex code
```

**Suggested:**
```php
// Simplified code
```

**Benefits:**
- Improved readability
- Reduced cognitive load
- Easier testing
- Better reusability
```

Related Skills

suggest-testability-improvements

59
from dykyi-roman/awesome-claude-code

Suggests testability improvements for PHP code. Provides DI refactoring suggestions, mock opportunities, interface extraction, testing strategy recommendations.

yii-knowledge

59
from dykyi-roman/awesome-claude-code

Yii framework knowledge base. Provides Yii3 modular architecture, DDD integration, PSR-7/PSR-15 compliance, persistence, DI, security (RBAC, auth), event system (PSR-14), queue/jobs, infrastructure components (cache, rate limiter, HTTP client), testing, and antipatterns for Yii PHP projects.

troubleshooting-template

59
from dykyi-roman/awesome-claude-code

Generates troubleshooting guides and FAQ sections for PHP projects. Creates problem-solution documentation.

trace-request-lifecycle

59
from dykyi-roman/awesome-claude-code

Traces full request lifecycle from Router through Middleware, Controller, UseCase, Repository to Response. Documents HTTP methods, routes, middleware stack, response codes, and error handling paths.

trace-data-transformation

59
from dykyi-roman/awesome-claude-code

Maps data transformation chains — Request DTO to Command to Entity to Response DTO. Identifies mappers, serializers, type conversions, and data loss points across layer boundaries.

testing-knowledge

59
from dykyi-roman/awesome-claude-code

Testing knowledge base for PHP 8.4 projects. Provides testing pyramid, AAA pattern, naming conventions, isolation principles, DDD testing guidelines, and PHPUnit patterns.

task-progress-knowledge

59
from dykyi-roman/awesome-claude-code

TaskCreate pattern guidelines for progress tracking in coordinator agents

symfony-knowledge

59
from dykyi-roman/awesome-claude-code

Symfony framework knowledge base. Provides architecture, DDD integration, persistence, DI, security, messenger, workflow, events, infrastructure components, testing, and antipatterns for Symfony PHP projects.

stability-patterns-knowledge

59
from dykyi-roman/awesome-claude-code

Stability Patterns knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Circuit Breaker, Retry, Rate Limiter, Bulkhead, and resilience audits.

solid-knowledge

59
from dykyi-roman/awesome-claude-code

SOLID principles knowledge base for PHP 8.4 projects. Provides quick reference for SRP, OCP, LSP, ISP, DIP with detection patterns, PHP examples, and antipattern identification. Use for architecture audits and code quality reviews.

scan-codebase-structure

59
from dykyi-roman/awesome-claude-code

Scans directory tree to identify architectural layers (Domain, Application, Infrastructure, Presentation), detect framework (Symfony, Laravel, custom), count files per layer, and build project structure map.

scalability-knowledge

59
from dykyi-roman/awesome-claude-code

Scalability knowledge base. Provides vertical vs horizontal scaling, stateless design, session management, connection pooling, capacity planning, and PHP-FPM tuning for scalability audits.