Add PHP 8.2 strict types, PHPCS, and PHPStan linting#2
Merged
Conversation
- Bump minimum PHP to >=8.2, add declare(strict_types=1) to all files - Change composer type from package to library - Add PHPCS with WordPress coding standards (WPCS 3.0) - Add PHPStan at level 6 with szepeviktor/phpstan-wordpress - Add GitHub Actions CI workflow for linting on push/PR - Fix all esc_html__() calls to include shadow-taxonomy text domain - Add file/class docblocks, @param tags for WP-CLI methods - Suppress intentional slow query and unused parameter warnings - Fix return type issues in get_associated_post and get_related_post_by_slug - Simplify post_type_already_in_sync (remove always-true isset checks)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
>=8.2and addsdeclare(strict_types=1)to all PHP filesChanges
Composer
>=8.2, type changed frompackagetolibrarywpcs ^3.0,phpcompatibility-wp ^2.1,phpstan ^2.0,szepeviktor/phpstan-wordpress ^2.0,dealerdirect/phpcodesniffer-composer-installer ^1.0phpcs,phpcbf,phpstan,lintCode Quality Fixes
esc_html__()calls now include theshadow-taxonomytext domain@paramtags added for WP-CLI command$args/$assoc_argsparametersget_associated_post()andget_related_post_by_slug()(now properly returnsWP_Post|false)post_type_already_in_sync()— removed always-trueissetchecks and unreachable codephpcs:ignorecomments for slow DB queries and unused public API parametersNew Files
phpcs.xml.dist— WordPress coding standards configphpstan.neon.dist— PHPStan level 6 config (CLI file excluded from analysis due to missing WP-CLI stubs).github/workflows/lint.yml— CI pipelineBreaking Changes
Adding
declare(strict_types=1)means PHP will enforce strict type checking for function arguments in these files. Callers passing incorrect types (e.g. string where int is expected) will now getTypeErrorinstead of silent coercion.