[PHP 8.4] Fix implicitly nullable type declarations

Created on 15 April 2025, 5 months ago

Problem/Motivation

In PHP 8.4, declaring functions/methods with parameters containing null as a default value, but without null as one of the types (either as a nullable syntax or as a Union type with null) is deprecated.

https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullabl...

Steps to reproduce

phpcs --standard=SlevomatCodingStandard --sniffs=SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue


FILE: /app/docroot/modules/contrib/aggregator/src/Plugin/Block/AggregatorFeedBlock.php
---------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------
 64 | ERROR | [x] Parameter $logger_factory has null default value, but is not marked as nullable.
---------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------


FILE: /app/docroot/modules/contrib/aggregator/tests/src/Functional/migrate_drupal_ui/MigrateUpgradeExecuteTestBase.php
----------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------
 44 | ERROR | [x] Parameter $available_paths has null default value, but is not marked as nullable.
 44 | ERROR | [x] Parameter $missing_paths has null default value, but is not marked as nullable.
----------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------


FILE: /app/docroot/modules/contrib/aggregator/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php
----------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------
 75 | ERROR | [x] Parameter $settings has null default value, but is not marked as nullable.
----------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------


FILE: /app/docroot/modules/contrib/aggregator/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
----------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------
 75 | ERROR | [x] Parameter $settings has null default value, but is not marked as nullable.
----------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------
πŸ“Œ Task
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡·πŸ‡ΊRussia kiseleva.t

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

Merge Requests

Comments & Activities

  • Issue created by @kiseleva.t
  • Pipeline finished with Success
    5 months ago
    Total: 343s
    #473580
  • Status changed to Needs review about 2 months ago
  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

    Added a commit to resolve a deprecation notice I've been hitting on a production site:

    Deprecated function: Drupal\aggregator\ZfExtensionManagerSfContainer::setContainer(): Implicitly marking parameter $container as nullable is deprecated, the explicit nullable type must be used instead
  • Pipeline finished with Failed
    about 2 months ago
    Total: 324s
    #554532
  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

    Tests are failing, but I don't think it's related to this MR, as tests are also failing on the 2.x-dev branch

    So I think this could be RTBC?

  • First commit to issue fork.
  • Pipeline finished with Skipped
    24 days ago
    #582631
  • πŸ‡ΊπŸ‡ΈUnited States dcam

    We need to expand the test environments we use anyway, but if there's a bug in the next version of PHP then we really need to test with it. So I updated .gitlab-ci.yml.

    I did a temporary reversion of the fixes to see what might fail. Then I put the changes back after I satisfied my curiosity.

    This looks good to me. Thank you both!

  • πŸ‡ΊπŸ‡ΈUnited States dcam

    dcam β†’ changed the visibility of the branch 3519195-php-8.4-fix to hidden.

Production build 0.71.5 2024