Add declare( strict_types = 1 ) to all PHP files#2424
Add declare( strict_types = 1 ) to all PHP files#2424westonruter merged 13 commits intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@westonruter would appreciate a quick look when you have a moment 🙏 |
| @@ -1,4 +1,5 @@ | |||
| <?php | |||
| declare( strict_types = 1 ); | |||
There was a problem hiding this comment.
Should be after the plugin info.
There was a problem hiding this comment.
Good catch, thanks! Moved it after the plugin header.
| * @package performance | ||
| */ | ||
|
|
||
| declare( strict_types = 1 ); |
There was a problem hiding this comment.
| declare( strict_types = 1 ); | |
| declare( strict_types = 1 ); |
westonruter
left a comment
There was a problem hiding this comment.
Thanks for the PR.
In addition to the trivial PHPCS issue which I left a suggestion for, there are unit test failures related to the new strict types. This will need to be fixed.
|
@meravi why remove the strict types? The underlying type problem should be fixed so the strict types can exist in all the files. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #2424 +/- ##
=======================================
Coverage 69.33% 69.33%
=======================================
Files 90 90
Lines 7749 7749
=======================================
Hits 5373 5373
Misses 2376 2376
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I reverted it temporarily for testing, but it’s added back now. |
|
@meravi ok, you can see that the unit tests are still failing. Once they are passing this will be ready for review. |
I’ve fixed the issues, and the unit tests are now passing 🟢 |
…options/helper.php Co-authored-by: Weston Ruter <westonruter@gmail.com>
…options/helper.php Co-authored-by: Weston Ruter <westonruter@gmail.com>
…options/helper.php Co-authored-by: Weston Ruter <westonruter@gmail.com>
There was a problem hiding this comment.
Pull request overview
Enables PHP strict typing across the Performance Lab monorepo by adding declare( strict_types = 1 ); at the top of PHP source files, aligning the codebase with the stricter type-safety expectations already implied by PHPStan level 8 (Issue #2348).
Changes:
- Added
declare( strict_types = 1 );to PHP plugin entrypoints, helpers, and includes across multiple plugins. - Updated the autoloaded-options Site Health helper to ensure option values are stringified before calling
strlen()(to avoid type errors with non-string cached values).
Reviewed changes
Copilot reviewed 102 out of 102 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/webp-uploads/uninstall.php | Add strict_types declaration. |
| plugins/webp-uploads/settings.php | Add strict_types declaration. |
| plugins/webp-uploads/rest-api.php | Add strict_types declaration. |
| plugins/webp-uploads/picture-element.php | Add strict_types declaration. |
| plugins/webp-uploads/load.php | Add strict_types declaration. |
| plugins/webp-uploads/image-edit.php | Add strict_types declaration. |
| plugins/webp-uploads/hooks.php | Add strict_types declaration. |
| plugins/webp-uploads/helper.php | Add strict_types declaration. |
| plugins/webp-uploads/deprecated.php | Add strict_types declaration. |
| plugins/web-worker-offloading/third-party/woocommerce.php | Add strict_types declaration. |
| plugins/web-worker-offloading/third-party/seo-by-rank-math.php | Add strict_types declaration. |
| plugins/web-worker-offloading/third-party/google-site-kit.php | Add strict_types declaration. |
| plugins/web-worker-offloading/third-party.php | Add strict_types declaration. |
| plugins/web-worker-offloading/load.php | Add strict_types declaration. |
| plugins/web-worker-offloading/hooks.php | Add strict_types declaration. |
| plugins/web-worker-offloading/helper.php | Add strict_types declaration. |
| plugins/view-transitions/view-transitions.php | Add strict_types declaration. |
| plugins/view-transitions/uninstall.php | Add strict_types declaration. |
| plugins/view-transitions/includes/theme.php | Add strict_types declaration. |
| plugins/view-transitions/includes/settings.php | Add strict_types declaration. |
| plugins/view-transitions/includes/functions.php | Add strict_types declaration. |
| plugins/view-transitions/includes/class-plvt-view-transition-animation.php | Add strict_types declaration. |
| plugins/view-transitions/includes/class-plvt-view-transition-animation-registry.php | Add strict_types declaration. |
| plugins/view-transitions/includes/admin.php | Add strict_types declaration. |
| plugins/view-transitions/hooks.php | Add strict_types declaration. |
| plugins/speculation-rules/wp-core-api.php | Add strict_types declaration. |
| plugins/speculation-rules/uninstall.php | Add strict_types declaration. |
| plugins/speculation-rules/settings.php | Add strict_types declaration. |
| plugins/speculation-rules/plugin-api.php | Add strict_types declaration. |
| plugins/speculation-rules/load.php | Add strict_types declaration. |
| plugins/speculation-rules/hooks.php | Add strict_types declaration. |
| plugins/speculation-rules/class-plsr-url-pattern-prefixer.php | Add strict_types declaration. |
| plugins/performance-lab/load.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/webp-support/hooks.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/webp-support/helper.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/load.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/effective-asset-cache-headers/hooks.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/effective-asset-cache-headers/helper.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/bfcache-compatibility-headers/hooks.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/bfcache-compatibility-headers/helper.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/avif-support/hooks.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/avif-support/helper.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/avif-headers/hooks.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/avif-headers/helper.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/audit-enqueued-assets/hooks.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/audit-enqueued-assets/helper.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/audit-autoloaded-options/hooks.php | Add strict_types declaration. |
| plugins/performance-lab/includes/site-health/audit-autoloaded-options/helper.php | Add strict_types declaration and ensure non-string option values are serialized before strlen(). |
| plugins/performance-lab/includes/server-timing/object-cache.copy.php | Add strict_types declaration. |
| plugins/performance-lab/includes/server-timing/load.php | Add strict_types declaration. |
| plugins/performance-lab/includes/server-timing/hooks.php | Add strict_types declaration. |
| plugins/performance-lab/includes/server-timing/defaults.php | Add strict_types declaration. |
| plugins/performance-lab/includes/server-timing/class-perflab-server-timing.php | Add strict_types declaration. |
| plugins/performance-lab/includes/server-timing/class-perflab-server-timing-metric.php | Add strict_types declaration. |
| plugins/performance-lab/includes/admin/server-timing.php | Add strict_types declaration. |
| plugins/performance-lab/includes/admin/rest-api.php | Add strict_types declaration. |
| plugins/performance-lab/includes/admin/plugins.php | Add strict_types declaration. |
| plugins/performance-lab/includes/admin/load.php | Add strict_types declaration. |
| plugins/optimization-detective/uninstall.php | Add strict_types declaration. |
| plugins/optimization-detective/storage/data.php | Add strict_types declaration. |
| plugins/optimization-detective/storage/class-od-url-metrics-post-type.php | Add strict_types declaration. |
| plugins/optimization-detective/storage/class-od-url-metric-store-request-context.php | Add strict_types declaration. |
| plugins/optimization-detective/storage/class-od-storage-lock.php | Add strict_types declaration. |
| plugins/optimization-detective/storage/class-od-rest-url-metrics-store-endpoint.php | Add strict_types declaration. |
| plugins/optimization-detective/site-health.php | Add strict_types declaration. |
| plugins/optimization-detective/optimization.php | Add strict_types declaration. |
| plugins/optimization-detective/load.php | Add strict_types declaration. |
| plugins/optimization-detective/hooks.php | Add strict_types declaration. |
| plugins/optimization-detective/helper.php | Add strict_types declaration. |
| plugins/optimization-detective/detection.php | Add strict_types declaration. |
| plugins/optimization-detective/deprecated.php | Add strict_types declaration. |
| plugins/optimization-detective/class-od-visited-tag-state.php | Add strict_types declaration. |
| plugins/optimization-detective/class-od-url-metric.php | Add strict_types declaration. |
| plugins/optimization-detective/class-od-url-metric-group.php | Add strict_types declaration. |
| plugins/optimization-detective/class-od-url-metric-group-collection.php | Add strict_types declaration. |
| plugins/optimization-detective/class-od-template-optimization-context.php | Add strict_types declaration. |
| plugins/optimization-detective/class-od-tag-visitor-registry.php | Add strict_types declaration. |
| plugins/optimization-detective/class-od-tag-visitor-context.php | Add strict_types declaration. |
| plugins/optimization-detective/class-od-strict-url-metric.php | Add strict_types declaration. |
| plugins/optimization-detective/class-od-link-collection.php | Add strict_types declaration. |
| plugins/optimization-detective/class-od-html-tag-processor.php | Add strict_types declaration. |
| plugins/optimization-detective/class-od-element.php | Add strict_types declaration. |
| plugins/optimization-detective/class-od-data-validation-exception.php | Add strict_types declaration. |
| plugins/image-prioritizer/load.php | Add strict_types declaration. |
| plugins/image-prioritizer/hooks.php | Add strict_types declaration. |
| plugins/image-prioritizer/helper.php | Add strict_types declaration. |
| plugins/image-prioritizer/class-image-prioritizer-video-tag-visitor.php | Add strict_types declaration. |
| plugins/image-prioritizer/class-image-prioritizer-tag-visitor.php | Add strict_types declaration. |
| plugins/image-prioritizer/class-image-prioritizer-img-tag-visitor.php | Add strict_types declaration. |
| plugins/image-prioritizer/class-image-prioritizer-background-image-styled-tag-visitor.php | Add strict_types declaration. |
| plugins/embed-optimizer/load.php | Add strict_types declaration. |
| plugins/embed-optimizer/hooks.php | Add strict_types declaration. |
| plugins/embed-optimizer/helper.php | Add strict_types declaration. |
| plugins/embed-optimizer/class-embed-optimizer-tag-visitor.php | Add strict_types declaration. |
| plugins/dominant-color-images/load.php | Add strict_types declaration. |
| plugins/dominant-color-images/hooks.php | Add strict_types declaration. |
| plugins/dominant-color-images/helper.php | Add strict_types declaration. |
| plugins/dominant-color-images/class-dominant-color-image-editor-imagick.php | Add strict_types declaration. |
| plugins/dominant-color-images/class-dominant-color-image-editor-gd.php | Add strict_types declaration. |
| plugins/auto-sizes/hooks.php | Add strict_types declaration. |
| plugins/auto-sizes/auto-sizes.php | Add strict_types declaration. |
| performance.php | Add strict_types declaration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@mukeshpanchal27 Are you having trouble running PHPUnit locally? I'm trying This used to work. See #2437 |
Adds
declare( strict_types = 1 );to all PHP source files across the monorepo.Fixes #2348