// ❌ BAD - Old implementation commented out// public function processOrder(Order $order)// {// $order->status = 'processing';// $order->save();// // ... 20 lines of old code// }public function processOrder(Order $order){ $this->orderService->process($order);}// ✅ GOOD - Remove commented codepublic function processOrder(Order $order){ $this->orderService->process($order);}
// ❌ BAD - Keeping old code for reference// Old validation logic:// if (strlen($email) < 5) {// throw new ValidationException('Email too short');// }// if (!str_contains($email, '@')) {// throw new ValidationException('Invalid email');// }// Current validation$request->validate(['email' => 'required|email']);// ✅ GOOD - Remove and use git log if needed$request->validate(['email' => 'required|email']);// If you need to see old code:// git log -p app/Http/Controllers/UserController.php
// ❌ BAD - Commented code with explanation// This was the old way to calculate discounts:// $discount = 0;// if ($order->total > 100) {// $discount = $order->total * 0.1;// }// if ($order->user->isPremium()) {// $discount += $order->total * 0.05;// }// Current implementation$discount = $this->discountCalculator->calculate($order);// ✅ GOOD - Move to documentation// See docs/discount-calculation.md for historical context$discount = $this->discountCalculator->calculate($order);
// ❌ BAD - Commented debug code// var_dump($user);// print_r($order->toArray());// die('Debug point');public function processOrder(Order $order){ // Actual code}// ✅ GOOD - Use proper loggingpublic function processOrder(Order $order){ Log::debug('Processing order', ['order_id' => $order->id]); // Actual code}
Commented Code Analyzer
commented-codeWhat This Checks
Why It Matters
How to Fix
Quick Fix (2 minutes)
Remove commented code and rely on version control:
Proper Fix (5 minutes)
1: Remove Old Implementation
2: Use Git for History
3: Extract to Documentation
4: Remove Debug Code
5: Remove Alternative Implementations
6: Remove Conditional Code Blocks
7: Customize ShieldCI Settings (Optional)
To customize the commented code detection sensitivity, publish the config:
Then in
config/shieldci.php:Configuration Guide
min_consecutive_lines: Controls the minimum number of lines required to flag a block
max_neutral_lines: Controls spacing tolerance within comment blocks
code_score_threshold: Controls what counts as "code" vs documentation
$variablementions (recommended)function,class,ifstatementsReferences
Related Analyzers