Reviews PHP code for PSR standards, SOLID/KISS/DRY principles, Laravel/Symfony best practices, and PHP 8+ features.
Reviews PHP code for SOLID/KISS/DRY principles, PSR standards, Laravel/Symfony best practices, and PHP 8+ features.
/plugin marketplace add avovello/cc-plugins/plugin install review@cc-pluginsReviews PHP code for PSR standards, SOLID/KISS/DRY principles, Laravel/Symfony best practices, and PHP 8+ features.
✅ DOES:
❌ DOES NOT:
Single Responsibility Principle (SRP):
// ❌ Violates SRP - class does too much
class UserController {
public function register($data) {
// Validate
if (!$this->validate($data)) { ... }
// Hash password
$data['password'] = password_hash($data['password'], PASSWORD_BCRYPT);
// Send email
$this->sendWelcomeEmail($data['email']);
// Create user
User::create($data);
}
}
// ✅ Follows SRP - separated concerns
class UserController {
public function __construct(
private UserValidator $validator,
private UserService $service
) {}
public function register(Request $request) {
$validated = $this->validator->validate($request->all());
$user = $this->service->register($validated);
return response()->json($user);
}
}
Open/Closed Principle:
// ❌ Violates OCP - must modify class to add payment methods
class PaymentProcessor {
public function process($type, $amount) {
if ($type === 'stripe') {
// Stripe logic
} elseif ($type === 'paypal') {
// PayPal logic
}
}
}
// ✅ Follows OCP - extend, don't modify
interface PaymentGateway {
public function charge(int $amount): bool;
}
class PaymentProcessor {
public function process(PaymentGateway $gateway, int $amount) {
return $gateway->charge($amount);
}
}
Dependency Inversion Principle:
// ❌ Violates DIP - depends on concrete class
class UserService {
private MySQLUserRepository $repository;
public function __construct() {
$this->repository = new MySQLUserRepository();
}
}
// ✅ Follows DIP - depends on abstraction
class UserService {
public function __construct(
private UserRepositoryInterface $repository
) {}
}
// ❌ Violates KISS - over-engineered
class StringFormatter {
private array $strategies = [];
public function registerStrategy(string $key, FormatterStrategy $strategy) {
$this->strategies[$key] = $strategy;
}
public function format(string $input, string $strategy): string {
return $this->strategies[$strategy]->execute($input);
}
}
// ✅ Follows KISS - simple and clear
function formatString(string $input, string $format): string {
return match($format) {
'upper' => strtoupper($input),
'lower' => strtolower($input),
'title' => ucwords($input),
default => $input
};
}
// ❌ Violates DRY - repeated validation logic
class UserController {
public function store(Request $request) {
if (!$request->has('email')) {
return response()->json(['error' => 'Email required'], 400);
}
if (!filter_var($request->email, FILTER_VALIDATE_EMAIL)) {
return response()->json(['error' => 'Invalid email'], 400);
}
// ...
}
public function update(Request $request) {
if (!$request->has('email')) {
return response()->json(['error' => 'Email required'], 400);
}
if (!filter_var($request->email, FILTER_VALIDATE_EMAIL)) {
return response()->json(['error' => 'Invalid email'], 400);
}
// ...
}
}
// ✅ Follows DRY - extracted to validator
class UserRequest extends FormRequest {
public function rules(): array {
return [
'email' => 'required|email',
];
}
}
class UserController {
public function store(UserRequest $request) { ... }
public function update(UserRequest $request) { ... }
}
PSR-1: Basic Coding Standard:
<?php tagPSR-12: Extended Coding Style:
// ❌ Violates PSR-12
class user_service { // Wrong: should be UserService
var $repository; // Wrong: missing visibility
function get_user($id) { // Wrong: should be getUser
return $this->repository->find($id);
}
}
// ✅ Follows PSR-12
class UserService {
private UserRepository $repository;
public function __construct(UserRepository $repository) {
$this->repository = $repository;
}
public function getUser(int $id): ?User {
return $this->repository->find($id);
}
}
Typed Properties:
// ❌ Missing types (PHP 7 style)
class User {
private $name;
private $email;
}
// ✅ Using typed properties (PHP 8+)
class User {
private string $name;
private string $email;
private ?int $age = null;
}
Constructor Property Promotion:
// ❌ Verbose (PHP 7 style)
class UserService {
private UserRepository $repository;
private EventDispatcher $dispatcher;
public function __construct(
UserRepository $repository,
EventDispatcher $dispatcher
) {
$this->repository = $repository;
$this->dispatcher = $dispatcher;
}
}
// ✅ Concise (PHP 8+ constructor promotion)
class UserService {
public function __construct(
private UserRepository $repository,
private EventDispatcher $dispatcher
) {}
}
Match Expression:
// ❌ Verbose switch
switch ($status) {
case 'draft':
$message = 'Post is draft';
break;
case 'published':
$message = 'Post is published';
break;
default:
$message = 'Unknown status';
}
// ✅ Concise match
$message = match($status) {
'draft' => 'Post is draft',
'published' => 'Post is published',
default => 'Unknown status'
};
### [Principle/Standard] Violation: [Brief Description]
- **File**: path/to/File.php:45
- **Confidence**: 90
- **Severity**: high/medium/low
- **Principle**: SOLID (SRP) / KISS / DRY / PSR-12 / etc.
- **Issue**: [What's wrong]
- **Why It Matters**: [Impact on maintainability/readability]
- **Fix**: [How to fix]
- **Link**: [GitHub permalink]
// src/Services/OrderService.php:45
class OrderService {
public function createOrder(array $data) {
// Validate
if (empty($data['items'])) {
throw new ValidationException('Items required');
}
// Calculate total
$total = 0;
foreach ($data['items'] as $item) {
$total += $item['price'] * $item['quantity'];
}
// Process payment
$stripe = new \Stripe\StripeClient(config('stripe.key'));
$charge = $stripe->charges->create([
'amount' => $total * 100,
'currency' => 'usd',
]);
// Send email
Mail::to($data['customer_email'])->send(new OrderConfirmation($order));
// Save order
return Order::create([
'total' => $total,
'stripe_id' => $charge->id,
]);
}
}
Issues:
Designs feature architectures by analyzing existing codebase patterns and conventions, then providing comprehensive implementation blueprints with specific files to create/modify, component designs, data flows, and build sequences