Skip to content

Latest commit

 

History

History
94 lines (68 loc) · 1.8 KB

type_declaration_spaces.rst

File metadata and controls

94 lines (68 loc) · 1.8 KB

Rule type_declaration_spaces

Ensure single space between a variable and its type declaration in function arguments and properties.

Configuration

elements

Structural elements where the spacing after the type declaration should be fixed.

Allowed values: a subset of ['function', 'property']

Default value: ['function', 'property']

Examples

Example #1

Default configuration.

--- Original
+++ New
 <?php
 class Bar
 {
-    private string    $a;
-    private bool   $b;
+    private string $a;
+    private bool $b;

-    public function __invoke(array   $c) {}
+    public function __invoke(array $c) {}
 }

Example #2

With configuration: ['elements' => ['function']].

--- Original
+++ New
 <?php
 class Foo
 {
     public int   $bar;

-    public function baz(string     $a)
+    public function baz(string $a)
     {
-        return fn(bool    $c): string => (string) $c;
+        return fn(bool $c): string => (string) $c;
     }
 }

Example #3

With configuration: ['elements' => ['property']].

--- Original
+++ New
 <?php
 class Foo
 {
-    public int   $bar;
+    public int $bar;

     public function baz(string     $a) {}
 }

Rule sets

The rule is part of the following rule sets:

@PhpCsFixer
Using the @PhpCsFixer rule set will enable the type_declaration_spaces rule with the default config.
@Symfony
Using the @Symfony rule set will enable the type_declaration_spaces rule with the default config.