The Three Rules
- Read before changing. Tell the AI to read the file(s) first, then make changes. "Read UserModel.php and then change the create() method to..."
- Say what must not change. "Change only the validation logic. Do not change the method signature or the database query."
- Review the diff. In Claude Code, see every change before accepting. In Cursor, review the diff view. Never accept blind changes to existing files.
Change Behavior
Read UserModel::create(). Change it so that:
- Email must be unique (throw DuplicateEmailException if exists)
- Name must be 2-100 characters
- Phone number is optional but if provided must be 10 digits
Change only the validation section, not the INSERT query.
# Change a calculation:
> In OrderModel::calculateTotal(), change the tax rate from
18% to the value stored in config.php as TAX_RATE constant.
Also add a 5% discount if the user has role 'premium'.
# Change how data is returned:
> Read ProductModel::findAll(). Change it to return products
sorted by popularity (a 'views' column) by default instead of created_at.
Add an optional $sortBy parameter ('popularity', 'price', 'newest').
# Change access control:
> Update AuthMiddleware::check() so that:
- Public routes (/login, /register, /about) do not require authentication
- /admin/* routes require role='admin'
- All other routes require any authenticated user
Read the current check() method first.
Change UI / Styling
# Change the entire color scheme:
> Read assets/css/app.css. Change the color scheme from blue (#1a56db)
to a green theme (#16a34a primary, #14532d dark).
Update all CSS variables and any hard-coded hex values.
# Redesign a section:
> Read views/projects/index.php. Change the project listing from
a card grid to a table view with columns:
Project Name, Owner, Tasks (count), Status, Last Updated, Actions.
Keep the existing PHP logic, only change the HTML.
# Add responsive behavior:
> Read views/admin/users.php. The table breaks on mobile.
Make it responsive: on screens < 768px, hide the 'Created At' and
'Last Login' columns, stack the Action buttons vertically.
# Update to a newer Bootstrap version:
> Read includes/header.php and all view files.
Update from Bootstrap 4 to Bootstrap 5:
- mr-/ml- -> me-/ms-
- text-left -> text-start
- data-toggle -> data-bs-toggle
- data-target -> data-bs-target
- Remove jQuery dependency from Bootstrap components
Rename and Move Code
# Rename a method used everywhere:
> Rename UserModel::getUser() to UserModel::findById() across the entire codebase.
Find every file that calls ->getUser( and update it.
Do not change any other methods.
# Move logic to a service class:
> In AuthController, the processLogin() method has 60 lines of
password verification and session management logic.
Extract this to a new class AuthService::login(string $email, string $password, bool $remember): bool
AuthController should call AuthService::login() with 3 lines of code.
# Move config to environment variables:
> Find every hardcoded database credential, API key, or URL in the codebase.
Move them to a .env file and read them with getenv() in config/db.php and config/app.php.
Create .env.example with placeholder values.
Add .env to .gitignore.
Update Dependencies
# Update a PHP package:
> Read composer.json and all files that use the PHPMailer library.
Update from PHPMailer 5.x to PHPMailer 6.x.
The API changed: list the specific method and property changes,
then update all usages in the code.
# Replace jQuery with vanilla JS:
> Read assets/js/main.js. This file uses jQuery.
Rewrite it to use vanilla JavaScript (no jQuery dependency).
Focus on: DOM manipulation, event listeners, AJAX calls (use fetch()).
# Upgrade PHP version:
> Read all .php files and find any code that is deprecated in PHP 8.2:
- ereg_replace (use preg_replace)
- each() (use foreach)
- create_function() (use arrow functions)
- Old-style constructor (use __construct)
List all issues found and fix them.
Replace a Component or Library
# Replace file upload library:
> The app uses a custom file upload function in functions.php.
Replace it with the Flysystem library (already in composer.json).
Read the existing function first. Create a new FileUploadService class
that uses Flysystem but exposes the same interface as the old function.
Update all callers to use the new service.
# Replace email solution:
> The app uses PHP mail() for all emails. Read all files that call mail().
Replace them to use Symfony Mailer (add to composer.json).
Create an EmailService wrapper so callers do not need to know about Symfony Mailer.
# Replace in-memory session with Redis:
> The app uses PHP sessions ($_SESSION). Replace session storage with Redis
using session_set_save_handler. Existing code that reads/writes $_SESSION
should continue to work unchanged - only the storage backend changes.
Add redis connection config to config/app.php.