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
core/modules/contrib/default_content$ ../../../vendor/bin/phpcs --standard=SlevomatCodingStandard --sniffs=SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue .
FILE: /home/andypost/www/core/modules/contrib/default_content/src/ContentFileStorage.php
---------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------
67 | ERROR | [x] Parameter $filename has null default value, but is not marked as nullable.
---------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------
FILE: /home/andypost/www/core/modules/contrib/default_content/src/ContentFileStorageInterface.php
-------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------
36 | ERROR | [x] Parameter $filename has null default value, but is not marked as nullable.
-------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------
FILE: /home/andypost/www/core/modules/contrib/default_content/src/Importer.php
-------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------
159 | ERROR | [x] Parameter $file_system has null default value, but is not marked as nullable.
-------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------
Time: 420ms; Memory: 14MB
Proposed resolution
Update all instances of such declarations to use Union types or nullable types.
This is a rather big set of changes. To replicate the results:
cd core
../vendor/bin/phpcbf --standard=SlevomatCodingStandard --sniffs=SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue lib modules themes profiles tests
or
php-cs-fixer fix . --rules nullable_type_declaration_for_default_null_value
Add SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue
sniffer to prevent new issues
Remaining tasks
User interface changes
API changes
Data model changes