---
name: PHP Unused Code Review
description: Identifies unused or dead code that can be safely removed from PHP codebase
version: 1.0.0
author: AI Code Review Tool
reviewType: unused-code
aliases:
  - php-unused
tags:
  - cleanup
  - refactoring
  - maintenance
  - php
language: php
lastModified: '2025-05-15'
---

# 🧠 PHP Unused Code Review

Act as a **PHP code cleanup expert with deep knowledge of static analysis**. Perform a detailed unused code review on the following PHP code. Analyze it using the checklist below and provide **specific recommendations** for dead code removal.

{{#if languageInstructions}}
{{{languageInstructions}}}
{{/if}}

> **Context**: This is an unused code focused review to identify and safely remove dead code from PHP codebases. The analysis may include results from static analysis tools like PHPStan, Psalm, or PHPCodeSniffer.

{{#if schemaInstructions}}
{{{schemaInstructions}}}
{{/if}}

---

## ✅ PHP Unused Code Evaluation Checklist

### 🗑️ Dead Code
- Are there any unused variables, functions, or classes?
- Are there unreachable code blocks (after return/die/exit)?
- Are there commented-out code blocks that should be removed?
- Are there any unused imports or dependencies (use statements)?
- Are there methods or functions that are defined but never called?

### 🛑 Redundant Code
- Are there duplicate functions or methods?
- Are there functions that perform the same task?
- Are there overly complex solutions that could be simplified?
- Are there reimplementations of PHP standard library functionality?
- Are there similar functions that could be consolidated?

### 📦 Deprecated Features
- Are there deprecated API usages?
- Are there uses of deprecated PHP functions or language features?
- Are there code blocks only used for backward compatibility?
- Are there references to deprecated PHP extensions or libraries?

### 🔄 Feature Flags & Conditional Code
- Are there unused feature flags or environment checks?
- Are there code blocks for features that were fully released?
- Are there code paths that are never executed?
- Are there conditions that always evaluate to the same value?
- Are there disabled test cases or testing utilities no longer in use?

### 🐘 PHP-Specific Issues
- Are there unused traits or interfaces?
- Are there unneeded magic methods (__get, __set, etc.)?
- Are there any debugging/var_dump/print_r statements that should be removed?
- Are there any unnecessary __construct() methods that don't do anything?
- Are there any unused public methods that could be made private or eliminated?

---

## 📤 Output Format
Provide clear, structured feedback grouped by impact level (High/Medium/Low). For each issue:

1. **Executive Summary**: Brief overview of the unused code analysis, including statistics on potentially removable code and expected benefits.

2. **High Impact Unused Code**: Code that's definitely unused and safe to remove
   - **Unused Code Issue**: Description of the unused code problem
   - **Location**: File and line number(s)
   - **Assessment**: Evidence that this code is truly unused (with reasoning)
   - **Suggested Action**: Clear recommendation for removal or refactoring
   - **Risk Level**: Potential impact of removing this code (Low/Medium/High)
   - **Before/After**: Code examples showing the code before and after removal

3. **Medium Impact Unused Code**: Code that's likely unused but requires verification

4. **Low Impact Unused Code**: Minor cleanup opportunities

5. **PHP-Specific Cleanup**: Focused section on PHP-specific unused elements:
   - Unused namespaces and use statements
   - Debug statements and commented code
   - Legacy PHP features and deprecated functions
   - Framework-specific unused elements (if applicable)

Example recommendation:

```php
// BEFORE: Unused method with debugging code
public function calculateValues($data)
{
    // Debug line from development
    var_dump($data);

    // This method is never called from anywhere in the codebase
    $result = [];
    foreach ($data as $item) {
        $result[] = $this->processItem($item);
    }
    return $result;
}

// AFTER: Remove the entire method if it's confirmed unused
// If the method might be called dynamically or through reflection,
// consider adding @deprecated PHPDoc and plan for proper removal
```

Focus on practical recommendations with clear justification. Include both easy fixes and more substantial cleanups. For PHP code, pay special attention to methods that might be called through reflection or dynamic invocation. In particular, be cautious about removing public methods that could be called dynamically or through dependency injection.

NOTE: Your suggestions are for manual implementation by the developer. This tool does not automatically apply fixes - it only provides recommendations that developers must review and implement themselves.
