Doctrine Annotation Coding Standard for PHP_CodeSniffer provides some additional sniffs centered on DocBlock annotations for Doctrine ORM.
This is currently very much work in progress and not yet very useful
Ideas for sniffs involve:
- make sure all JOIN mappings have a
@JoinColumnannotation, that explicitly statesnullable(this is because the default valuetrueis unexpected to many) - make sure
@varannotation exists and is in sync with the ORM configuration
The recommended way to install Doctrine Annotation Coding Standard is through Composer.
{ "require-dev": { "stesie/phpcs-doctrine-annotation-rules": "dev-master" } }Keep in mind that this is not a full coding standard, it just augments existing ones with extra checks on Doctrine annotations. If unsure, I highly recommend having a look at Slevomat Coding Standard.
Simply mention this (additional) standard in ruleset.xml:
<?xml version="1.0"?> <ruleset name="AcmeProject"> <rule ref="vendor/stesie/phpcs-doctrine-annotation-rules/src/DoctrineAnnotationCodingStandard/ruleset.xml" /> <!-- additional standards like slevomat --> </ruleset>To check your code base for violations, run PHP_CodeSniffer from the command line:
vendor/bin/phpcs --standard=ruleset.xml --extensions=php -sp src tests