Skip to content

feat: add three new V3→V4 rules and fix X509 rule bugs#5

Merged
terrafrost merged 1 commit into
mainfrom
claude/great-euclid-6efab7
May 18, 2026
Merged

feat: add three new V3→V4 rules and fix X509 rule bugs#5
terrafrost merged 1 commit into
mainfrom
claude/great-euclid-6efab7

Conversation

@terrafrost
Copy link
Copy Markdown
Member

Summary

  • Fix X509 rule bugs: load methods (loadCSR, loadCRL, loadSPKAC) were mapped to wrong target method names; SPKAC creation used the wrong class (CRL instead of SPKAC) and wrong node type (static call instead of new). Also removes the DecoratingNodeVisitor dependency that caused test failures when the V2→V3 and V3→V4 suites ran together (PHPStan's NodeScopeResolver is a singleton whose internal traverser can only be built once).
  • Add Namespace_ rule: renames phpseclib3\ to phpseclib4\ in use statements and explicit inline FQNs. Short names (e.g. RSA after use phpseclib3\Crypt\RSA) are left alone — renaming the use statement is sufficient. Skips phpseclib3\File\X509 (handled by the X509 rule) and phpseclib3\Crypt\Random (no phpseclib4 equivalent).
  • Add CryptRandom rule: replaces phpseclib3\Crypt\Random::string($n) (both via use import and as a fully-qualified call) with random_bytes($n), and removes the now-dead use import.
  • Add SFTPChmod rule: swaps the argument order of SFTP::chmod() from (mode, path[, recursive]) to (path, mode[, recursive]) to match the phpseclib4 signature. Only applies when the first argument is an integer literal; calls that already have a string first argument are left unchanged.

Test plan

  • php vendor/bin/phpunit tests/V3toV4 — all 35 tests pass
  • php vendor/bin/phpunit tests/ — all 99 tests pass (V2→V3 + V3→V4 combined)
  • Each new rule has fixtures covering the happy path, FQN variant, and a no-change skip case

🤖 Generated with Claude Code

Fix X509 rule:
- All file-class load methods (loadCSR, loadCRL, loadSPKAC) now correctly
  map to ::load() instead of ::loadCSR() / ::loadCRL() / ::loadSPKAC()
- SPKAC creation now generates `new SPKAC(...)` instead of a static call
  on the wrong CRL class
- Remove DecoratingNodeVisitor dependency (singleton conflict when running
  V2toV3 and V3toV4 test suites together); inline visitor logic into the
  rule itself using PhpParser\NodeFinder

Add three new rules:
- Namespace_: renames phpseclib3\ to phpseclib4\ in use statements and
  explicit FQNs; skips phpseclib3\File\X509 (handled by X509 rule) and
  phpseclib3\Crypt\Random (handled by CryptRandom rule)
- CryptRandom: replaces phpseclib3\Crypt\Random::string(n) with
  random_bytes(n) and removes the now-unused use import
- SFTPChmod: swaps the argument order of SFTP::chmod() calls from
  (mode, path) to (path, mode) to match the phpseclib4 signature

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@terrafrost terrafrost marked this pull request as ready for review May 18, 2026 00:59
@terrafrost terrafrost merged commit 779d344 into main May 18, 2026
3 checks passed
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.

1 participant