Code Quality Standards

Rules for maintaining high code quality across all projects.

# Code Quality Standards

## General Principles
1. Write code that is easy to read and understand
2. Follow the DRY (Don't Repeat Yourself) principle
3. Keep functions and methods small and focused
4. Use meaningful variable and function names
5. Document complex logic and decisions
6. In PHP, use data objects instead of arrays. Arrays should be converted to objects as soon as possible. If the project is using PHP 8.4 or higher, and set or get style methods are needed, use [property hooks](https://wiki.php.net/rfc/property-hooks). This does not apply to Drupal's render or form APIs.

## Error handling
1. Use exceptions for error conditions instead of NULL or FALSE returns.
2. Do not catch \Exception. Only catch exceptions that can be handled by a new code path.
3. When catching exceptions, always catch the narrowest exception possible. For example, if a function throws \RuntimeException, catch that instead of \Exception.
4. Do not catch exceptions simply to log them, unless the code is specifically trying to declare that the error state does not affect the caller of the method.
5. New exceptions should inherit from existing exception classes where possible.

## Code Style
- Use consistent indentation (2 or 4 spaces)
- Follow language-specific style guides
- Use proper spacing around operators
- Limit line length to 80-100 characters
- Use descriptive comments where necessary
- Always leave an empty new line at the end of a file

## Testing
- Write tests for all new functionality
- Maintain test coverage above 80%
- Include both unit and integration tests
- Test edge cases and error conditions
- Keep tests independent and isolated

## Documentation
- Document public APIs and interfaces
- Include usage examples
- Keep README files up to date
- Document configuration options
- Maintain changelog

## Performance
- Optimize critical code paths
- Use appropriate data structures
- Minimize database queries
- Implement caching where appropriate
- Monitor and profile performance