Fork me on GitHub
a Sensio Labs Product

Insomnia (v3.50.0) edition

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:

References

The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.