Rule doctrine_annotation_spaces
¶
Fixes spaces in Doctrine annotations.
Description¶
There must not be any space around parentheses; commas must be preceded by no space and followed by one space; there must be no space around named arguments assignment operator; there must be one space around array assignment operator.
Configuration¶
after_argument_assignments
¶
Whether to add, remove or ignore spaces after argument assignment operator.
Allowed types: null
and bool
Default value: false
after_array_assignments_colon
¶
Whether to add, remove or ignore spaces after array assignment :
operator.
Allowed types: null
and bool
Default value: true
after_array_assignments_equals
¶
Whether to add, remove or ignore spaces after array assignment =
operator.
Allowed types: null
and bool
Default value: true
around_commas
¶
Whether to fix spaces around commas.
Allowed types: bool
Default value: true
around_parentheses
¶
Whether to fix spaces around parentheses.
Allowed types: bool
Default value: true
before_argument_assignments
¶
Whether to add, remove or ignore spaces before argument assignment operator.
Allowed types: null
and bool
Default value: false
before_array_assignments_colon
¶
Whether to add, remove or ignore spaces before array :
assignment operator.
Allowed types: null
and bool
Default value: true
before_array_assignments_equals
¶
Whether to add, remove or ignore spaces before array =
assignment operator.
Allowed types: null
and bool
Default value: true
Examples¶
Example #1¶
Default configuration.
--- Original
+++ New
<?php
/**
- * @Foo ( )
+ * @Foo()
*/
class Bar {}
/**
- * @Foo("bar" ,"baz")
+ * @Foo("bar", "baz")
*/
class Bar2 {}
/**
- * @Foo(foo = "foo", bar = {"foo":"foo", "bar"="bar"})
+ * @Foo(foo="foo", bar={"foo" : "foo", "bar" = "bar"})
*/
class Bar3 {}
Example #2¶
With configuration: ['after_array_assignments_equals' => false, 'before_array_assignments_equals' => false]
.
--- Original
+++ New
<?php
/**
- * @Foo(foo = "foo", bar = {"foo":"foo", "bar"="bar"})
+ * @Foo(foo="foo", bar={"foo" : "foo", "bar"="bar"})
*/
class Bar {}
Rule sets¶
The rule is part of the following rule set:
@DoctrineAnnotation with config:
['before_array_assignments_colon' => false]
References¶
Fixer class: PhpCsFixer\Fixer\DoctrineAnnotation\DoctrineAnnotationSpacesFixer
Test class: PhpCsFixer\Tests\Fixer\DoctrineAnnotation\DoctrineAnnotationSpacesFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.