Code Monkey home page Code Monkey logo

phpcs-doctrine-annotation-rules's Introduction

Doctrine Annotation Coding Standard

Build Status Coverage Status PHPStan

Doctrine Annotation Coding Standard for PHP_CodeSniffer provides some additional sniffs centered on DocBlock annotations for Doctrine ORM.

Sniffs included in this standard

๐Ÿ”ง = Automatic errors fixing

DoctrineAnnotationCodingStandard.Commenting.ImplicitNullableJoinColumn

Applies to DocBlocks of properties that are mapped as either @ORM\ManyToOne or @ORM\OneToOne.

  • Checks for missing @ORM\JoinColumn annotation
  • If @ORM\JoinColumn exists, checks if nullable is implicitly assumed to be true

The default value of nullable of @ORM\JoinColumn is true (as opposed to @ORM\Column), which many DEVs are unaware of and hence have NULL-able associations where they should not have ones. This sniff ensures that the nullable-choice is made explicitly.

DoctrineAnnotationCodingStandard.Commenting.VarTag ๐Ÿ”ง

Applies to all DocBlocks of Doctrine-mapped properties.

  • Checks for missing @var tag
  • Checks the type stated by @var against actual type (according to Doctrine mapping)

This sniff supports automatic fixing with phpcbf.

Sniff provides the following settings:

  • doctrineExtraTypes: list of custom Doctrine types, that are mapped as strings (instead of objects)

Can be configured via ruleset.xml like so:

    <rule ref="DoctrineAnnotationCodingStandard.Commenting.VarTag">
        <properties>
            <property name="doctrineExtraTypes" type="array" value="CustomerType,CompanySizeType" />
        </properties>
    </rule>

Installation

The recommended way to install Doctrine Annotation Coding Standard is through Composer.

$ composer require --dev stesie/phpcs-doctrine-annotation-rules

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.

Using the standard as a whole

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

Fixing errors automatically

Sniffs in this standard marked by the ๐Ÿ”ง symbol support automatic fixing of coding standard violations. To fix your code automatically, run phpcbf insteand of phpcs:

vendor/bin/phpcbf --standard=ruleset.xml --extensions=php -sp src tests

phpcs-doctrine-annotation-rules's People

Contributors

afurculita avatar danionut90 avatar stesie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

phpcs-doctrine-annotation-rules's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.