Fork me on GitHub
a Sensio Labs Product

I ate three cookies πŸͺ (v3.40.2) edition

Rule phpdoc_to_property_typeΒΆ

EXPERIMENTAL: Takes @var annotation of non-mixed types and adjusts accordingly the property signature. Requires PHP >= 7.4.

WarningΒΆ

Using this rule is riskyΒΆ

This rule is EXPERIMENTAL and [1] is not covered with backward compatibility promise. [2] @var annotation is mandatory for the fixer to make changes, signatures of properties without it (no docblock) will not be fixed. [3] Manual actions might be required for newly typed properties that are read before initialization.

ConfigurationΒΆ

scalar_typesΒΆ

Fix also scalar types; may have unexpected behaviour due to PHP bad type coercion system.

Allowed types: bool

Default value: true

ExamplesΒΆ

Example #1ΒΆ

Default configuration.

--- Original
+++ New
 <?php
 class Foo {
     /** @var int */
-    private $foo;
+    private int $foo;
     /** @var \Traversable */
-    private $bar;
+    private \Traversable $bar;
 }

Example #2ΒΆ

With configuration: ['scalar_types' => false].

--- Original
+++ New
 <?php
 class Foo {
     /** @var int */
     private $foo;
     /** @var \Traversable */
-    private $bar;
+    private \Traversable $bar;
 }

Source classΒΆ

PhpCsFixer\Fixer\FunctionNotation\PhpdocToPropertyTypeFixer