php Rules
2 rules found for php
Avoid aliases for new routes in PHP
Only use route aliases for backward compatibility with renamed or moved routes. Do not add aliases to newly created routes. Bad: `php // Adding an alias to a new route Route::put('/api/users/{id}') ->alias('/api/user/{id}'); // Another framework example $router->map('GET', '/products/{productId}', 'ProductController::show') ->alias('product.show.alt'); ` Good: `php // New route without an alias Route::put('/api/users/{id}'); `
php
Prefer switch statements in PHP
Use switch statements when handling multiple attribute types. Bad: `php foreach ($attributes as $attribute) { if ($attribute->getAttribute('type') === Database::VAR_RELATIONSHIP) { // Handle relationship attribute } if ($attribute->getAttribute('type') === Database::VAR_STRING) { // Handle string attribute } } ` Good: `php foreach ($attributes as $attribute) { $attributeType = $attribute->getAttribute('type'); switch ($attributeType) { case Database::VAR_RELATIONSHIP: // Handle relationship attribute break; case Database::VAR_STRING: // Handle string attribute break; } } `
php