Allow omitting @var for strictly typed class properties

Created on 21 September 2021, over 3 years ago
Updated 17 January 2023, over 2 years ago

Problem/Motivation

With the introduction of PHP 7.4 the language now supports indicating what type a class property is (in older versions this was limited to PHP primitive types). In the current Drupal Coding Standards a @var annotation is required for class properties. However, since this information can now be added in code (when targetting at least PHP 7.4), those comments are often duplicated information that risk becoming out of sync.

Steps to reproduce

Proposed resolution

Adjust the coding standards to allow not adding a @var comment to class properties in case those properties have a type defined using PHP's typing system.

#3123282: Do not require @var tag if a property has typehint โ†’ provides a patch for coder that demonstrates this behaviour.

The following code would now be valid.

class Foo {
  
  /**
    * Where one can order a soda.
    */
  protected Bar $baz;

  /**
    * Some complex type that probably needs cleaning up in a future.
    * 
    * This type can not be represented in the PHP typesystem yet.
    *
    * @var int|string|NULL
    */
   public $someVar;

}

Remaining tasks

User interface changes

API changes

Data model changes

โœจ Feature request
Status

RTBC

Component

Coding Standards

Created by

๐Ÿ‡ณ๐Ÿ‡ฑNetherlands kingdutch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024