Hey fellow developers!
I wanted to start a discussion about the different types of sanity checks we use in our projects to ensure code quality, maintainability, and overall reliability before pushing changes live.
Sanity checks are critical in catching small but impactful issues early, whether it’s debugging leftovers, unused variables, or even forgotten dd()
statements in Laravel (guilty ). Sometimes, automated tools in our CI/CD pipelines help, and sometimes it’s manual—but the goal is always to ensure our code is polished and ready for production.
Here are some sanity checks I’ve used or seen:
1. Debugging Statements Check
- In Laravel, I’ve added a
grep
check in my GitLab CI pipeline to catchdd()
ordump()
functions before pushing to production. It fails the pipeline if any of those are found.
2. PHP Code Sniffer & PHPStan
- Using these tools to automatically enforce coding standards and prevent errors or unnecessary complexity in my PHP projects.
3. API Response Validation
- Adding sanity checks for expected JSON structure and response types when consuming APIs during testing phases.
4. Hardcoded URLs or Credentials
- Regularly scanning for hardcoded credentials, API keys, or URLs in the codebase. We’ve all seen the consequences of accidentally shipping a hardcoded password .
5. Unused Variables/Imports
- Sanity checks for unused variables, classes, or imports using static analysis tools to avoid unnecessary bloat in the code.
6. Database Queries
- Ensuring that SQL queries are properly optimized, and there aren’t any unintentional N+1 queries, especially in ORM-heavy projects.
I’d love to hear what sanity checks you all use!
Feel free to share any custom checks you’ve written, tools you rely on, or even the simple habits you’ve picked up over time that help you ship better code. Let’s build a comprehensive list that can benefit everyone!
Looking forward to your contributions!