Skip to content

chore: add static analysis (PHPCS + PHPStan) and CI - #9

Merged
vitormattos merged 8 commits into
mainfrom
chore/static-analysis
Sep 24, 2026
Merged

vitormattos merged 8 commits into
mainfrom
chore/static-analysis

Conversation

@YvesCesar

@YvesCesar YvesCesar commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

The plugin had no composer.json, no linting and no CI — the only check was the DCO bot. This adds a static analysis setup and fixes what the first run reported.

Tooling

  • composer.json — PHP >=8.1, dev dependencies only (PHPCS 3.13, WPCS 3.4, PHPCompatibilityWP, PHPStan 2.2 + phpstan-wordpress, WooCommerce stubs, parallel-lint) and the lint / cs / cs:fix / stan / ci scripts.
  • phpcs.xml.dist — a lean ruleset rather than the full WordPress-Extra + WordPress-Docs. The files mix tabs and spaces, so running phpcbf over the whole standard would bury the history in a formatting diff. It enables only WordPress.Security, WordPress.DB, WordPress.WP.I18n, the deprecated/global-override sniffs, PrefixAllGlobals (prefixes libresign / LIBRESIGN) and PHPCompatibilityWP with testVersion 8.1-.
  • phpstan.neon.dist — level 5, clean. The only ignoreErrors entry covers the wp-config.php salts (AUTH_KEY, SECURE_AUTH_SALT, NONCE_SALT), which PHPStan cannot see.
  • .github/workflows/ci.yml — a single static job on PHP 8.3 running composer lint, cs and stan.

wc_clean is registered as a custom sanitizing function, otherwise PHPCS reports four false positives on code that already sanitizes correctly.

Findings fixed

The first PHPCS run reported 11 issues, all in libresign-wp-customizations.php:

  • :205 the admin notice was echoed with interpolated variables and no escaping — now printf with esc_attr plus wp_kses_post, since the message intentionally carries an <a>.
  • :234 wp_die( __( 'Você não tem permissão…' ) ) had no text domain, so the string was never translatable, and no escaping either.
  • :621 $_SERVER['REQUEST_URI'] was only unslashed, never sanitized.
  • :721 the FAQ link is built as HTML and was passed raw to printf.
  • :788 and :832 $_GET['subscription_id'] and $_GET['libresign_confirm_subscription'] were passed straight into the lookup helper — now absint( wp_unslash( … ) ), which also clears the two NonceVerification warnings.

Verification

composer ci is green: no lint errors, no PHPCS violations, no PHPStan errors at level 5. The plugin still loads and stays active in the local stack.

Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
@YvesCesar
YvesCesar requested review from vitormattos and removed request for vitormattos September 14, 2026 21:32
@YvesCesar
YvesCesar marked this pull request as draft September 14, 2026 21:33
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Comment thread .github/workflows/phpstan.yml
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Comment thread .github/workflows/phpstan.yml
Comment thread .github/workflows/phpcs.yml Outdated
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Comment thread composer.json Outdated
Comment thread libresign-wp-customizations.php Outdated
Comment thread phpcs.xml.dist Outdated
Comment thread .github/workflows/php-lint.yml Outdated
@vitormattos
vitormattos added this pull request to stack #14 September 19, 2026 17:59
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
Signed-off-by: YvesCesar <yvesamorim73@gmail.com>

@vitormattos vitormattos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now. The requested changes were addressed and the remaining CI improvements are tracked in #15 as a follow-up.

@vitormattos
vitormattos merged commit d953d6d into main Sep 24, 2026
13 checks passed
@vitormattos
vitormattos deleted the chore/static-analysis branch September 24, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants