Problem/Motivation

With 2.x now targeting PHP ^8.1 we can leverage a number of improvements in PHP regarding code type.

Implementing type hints more broadly through the code will allow for better code parsing by tools including PHPStan reduce the risk of unseen errors in tfa and other ecosystem modules.

Steps to reproduce

Review Code

Proposed resolution

Add type hints to properties, parameters, and method/function returns

Remaining tasks

Patch

User interface changes

None

API changes

All code will now be type hinted, including interfaces, this will require those who implement our interfaces to also type hint their code.

Some code may have type-hint adjusted to be more accurate if the PHPDocs are not fully accurate, the majority of the code however is expected to match its existing documentation.

Data model changes

None expected.

Assigning this to myself as I'm also using this as a good reason to review the code and get better acquainted with its internals.

Issue fork tfa-3385496

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

cmlara created an issue. See original summary.

cmlara’s picture

Title: Add return, property, and parameter type hints to cod base » Add return, property, and parameter type hints to code

cmlara’s picture

Assigned: cmlara » Unassigned
Status: Active » Needs review

First round with return type hits where we have a solid API.

Parameter type hints where we have a well defined API, biggest exceptions are the plugin validate() method which has no defined interface and has type hints that conflict with the code (requesting an integer and passing it to a method requesting a string). Also skipped type hints where the parent interfaces or implementations do not allow adding such.

cmlara’s picture

  • cmlara committed fe00f774 on 2.x
    Issue #3385496: Add return, property, and parameter type hints to code
    
cmlara’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.