- Maintaining consistent code style is crucial in team development
- Configure PSR12 style in PHPStorm
File -> Settings -> Editor-> Code Style -> Set from -> select PSR12
Using PHP_CodeSniffer for Code Style Checks
-
Create
phpcs.xml
in project root for team-wide usage -
Configuration notes:
- Official documentation is limited - often requires debugging error messages
- Example: To disable
end xxx()
comments:- Search source code for
//end
- Locate
PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting::ClosingDeclarationCommentSniff
- Remove
<rule ref="Squiz.Commenting.ClosingDeclarationComment"/>
from config
- Search source code for
Static Analysis with phpstan
- Create
phpstan.neon
configuration in project root
Workflow Implementation
- Team members work on feature branches
- Merge to
dev
branch triggers git hook - Stage server performs:
- PHPUnit tests
- PHPCS style checks (with phpcbf auto-fix)
- PHPStan static analysis
- Successful checks trigger merge to master; failures trigger notifications
Configuration Notes
- For containerized testing:
- Share host machine’s SSH credentials:
volumes: # Share Git credentials - /root/.ssh:/home/laradock/.ssh
- Ensure proper permissions for SSH directory access