Problem/Motivation
Before we can add declare(strict_types=1) to existing code we need to fix strict type errors. We can detect some of these with phpstan, via the FunctionCallParametersCheck rule.
Steps to reproduce
To activate the FunctionCallParametersCheck rule we can add the following parameter to phpstan.neon.dist:
parameters:
checkFunctionArgumentTypes: true
Proposed resolution
Review detected errors and fix them in child issues.
- #3459170: Fix instances of ints passed to functions expecting strings
- #3461945: Fix instances of floats passed to functions expecting ints
- #3463440: Fix param docs identified by phpstan
- #3471932: Fix callables that are expected to return bool but don't
- #3471949: Allow passing MarkupInterface to AssertContentTrait::setRawContent
- #3473203: Fix use of ConstraintViolation instead of ConstraintViolationInterface in CKEditor5 tests>
- #3473214: Stop passing ints to DateTimePlus::createFromFormat and DrupalDateTime::createFromFormat>
- #3473228: Fix more var and param docs identified by phpstan
- #3542137: Fix strict type issues in SchemaCheckTrait
- #3542161: Fix phpdoc issues with variables passed to array functions
- #3552181: Stop passing null as the label to createEntityReferenceField
- #3552759: Fix more incorrect phpdoc type hints (part 1)
- #3554659: Fix more incorrect phpdoc type hints (part 2)
- #3554676: Fix more incorrect phpdoc type hints (part 3)
- #3552521: Fatal error caused by install_check_class_requirements
- #3557053: Stop passing null as $deserialization_target_class
- #3557514: Fix "expects int, string given" issues detected by phpstan
- #3567159: Fix "expects array<string>" issues detected by phpstan
phpstan-drupal: EntityReference formatter stubs
Remaining tasks
- #3558167: Fix "expects FooInterface, MockObject given" phpstan errors
- #3561385: Fix "expects FieldableEntityInterface" issues detected by phpstan
- #3471741: Fix null $cid in CacheCollector classes
- phpstan-drupal: Fix $offset type in ItemList::offsetExists
- Decide what to do after calling $storage->loadMultiple and passing the EntityInterface to functions expecting something more specific
- ...
- #3570870: Add checkFunctionArgumentTypes parameter to phpstan config
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3404246
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
Comment #3
mstrelan commentedThere are 271 errors identified in the code quality report, or 266 in the test report.
Comment #5
mstrelan commentedNot sure the best way to split this, so just started working on it. We can cherry-pick each fix to separate issues if we need to split it.
Comment #6
mstrelan commentedI don't think we need
checkArgumentsPassedByReferencehere as that isn't affected by strict types (AFAIK).Comment #7
mstrelan commentedRemoved the bit about excluding tests. Tests call out to non-test code, and there can exist errors.
Comment #8
mstrelan commentedComment #9
mstrelan commentedComment #10
mstrelan commentedComment #11
mstrelan commentedComment #12
mstrelan commentedComment #13
mstrelan commentedComment #14
mstrelan commentedComment #15
mstrelan commentedI rebased the MR hoping to see the number of errors go down since #3473228: Fix more var and param docs identified by phpstan, but it's actually gone up from 381 to 436.
Comment #16
spokje@mstrelan: Meh! Are the new additions all in the var/param docs region? Or were there a lot of additions to the baseline during that period?
Comment #17
mstrelan commented@spokje I didn't look at what they were. It wouldn't have been baseline additions, because these issues are only reported once the config is changed as per the MR here.
Comment #18
mstrelan commentedphpstan-drupal v2.0.6 fixed some issues with entity reference formatters, removing that from remaining tasks.
There are still 657 errors so we need some more child issues. Opened #3542137: Fix strict type issues in SchemaCheckTrait to resolve 112 of them.
Comment #19
mstrelan commentedComment #20
mstrelan commentedComment #21
mstrelan commentedUpdated remaining tasks and split fixed issues to its own list
Comment #23
mstrelan commentedUpdated remaining tasks