Create Project-Specific PHPStan and PHPCS Rules with AI Agents
TL;DR: Writing rules for AI agents helps, but AI is non-deterministic — violations will slip through. Enforce project-specific constraints with custom PHPStan/PHPCS rules for mechanical checking. Let an AI agent draft the custom rules for you, and you can implement them quickly. CLAUDE.md Alone Isn’t Enough If you’re using an AI agent like Claude Code, you probably write project rules in CLAUDE.md or rule files. Things like: “Use ‘Plan’ instead of the old term ‘Course’ everywhere in the code” “DateTime::createFromTimestamp() must always receive a timezone as the second argument” “Core domain classes must not call infrastructure directly” The agent respects these rules and writes compliant code — most of the time. But AI is non-deterministic. The same instruction doesn’t always produce the same output. When the context gets long or the agent is in the middle of a complex refactoring, it can “accidentally” generate code that violates the rules, even though they’re written right there in the rule files. ...