Standards check makes it difficult to enforce strict_types declaration

Created on 11 September 2024, 7 months ago

Problem/Motivation

This was previously discussed in #3407995-10: Add sniff for declare(strict_types=1); .

We introduced a standards check for declare(strict_types=1) in Add sniff for declare(strict_types=1); Needs review by leveraging the SlevomatCodingStandard.TypeHints.DeclareStrictTypes sniff. Since we don't (yet) want to require the presence of the strict types declaration in every file, the SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing check was excluded.

However the exclusion of this check now makes it unclear for contrib modules and Drupal projects how they can enforce the inclusion of the strict types declaration. Before this change a contrib / project could add the following to their ruleset, but this doesn't work any more:

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" />

The problem can be worked around by adding the following rule, but this is not self-evident:

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing">
  <severity>5</severity>
</rule>

Proposed resolution

Maybe we can propose a toggle to allow setting a coding standard for declare(strict_types=1) but not require it in the Slevomat project? Alternatively we can extend their DeclareStrictTypesSniff class or copy over the logic.

🐛 Bug report
Status

Active

Version

8.3

Component

Coder Sniffer

Created by

🇧🇬Bulgaria pfrenssen Sofia

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

Comments & Activities

Production build 0.71.5 2024