Skip to content

Add types to methods signatures and classes properties #21790

@cedric-anne

Description

@cedric-anne

The goal is to eventually ensure that all GLPI functions/methods have a declaration of the type of their arguments and return values, that all class properties are typed, and that the declaration declare(strict_types=1) is added to all PHP files.

Changing a method signature may cause incompatibility with existing plugin code if they override this method. Therefore, changing method signatures outside the scope of a new major version is not permitted.

In GLPI 11.x, we can add types via PHPDoc for public/protected elements and types via signature for private elements. As this does not cause any incompatibility issues for plugins, it can be done on an ongoing basis in the bugfixes branch.

Here is the proposed method for moving forward iteratively:

  • run the analysis of a specific file, for example vendor/bin/phpstan --memory-limit=-1 analyse --level 6 src/CommonGLPI.php (or make phpstan c=“analyze --level 6 src/CommonGLPI.php”);
  • correct certain errors in this file;
  • restart a global analysis at level 5 to check and correct any new errors detected, or add them to the baseline if they are too complex to correct.

The missingType.iterableValue rule has been disabled in order to focus primarily on native types, and because the precise definition of array $options arguments may generate cascading errors that will be time-consuming to fix. However, this rule will need to be reactivated eventually, so it is best to try to define iterable types precisely now.

Sub-issues

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions