Swap out direct file access test for phpcs sniff#2876
Conversation
📝 WalkthroughWalkthroughIntroduces a new PHP_CodeSniffer sniff to enforce direct file access protection checks (ABSPATH guard) across PHP files. The sniff is registered in the ruleset configuration, and the legacy PHPUnit test that previously validated this pattern manually is removed. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@phpcs-sniffs/Formidable/Sniffs/Security/AddDirectFileAccessCheckSniff.php`:
- Around line 139-160: The addAbspathCheck method calculates $insertAfter via
findInsertPosition but then ignores it — replace the opening-tag replacement and
the whitespace-cleanup to operate at $insertAfter (not $stackPtr) so the ABSPATH
check is inserted after any file-level docblock; also remove the unused $tokens
= $phpcsFile->getTokens(); declaration. Update the replaceToken call to use
$insertAfter and start the whitespace loop from $insertAfter + 1, keeping the
existing use of $nextNonWhitespace and fixer changeset calls.
🧹 Nitpick comments (1)
phpcs-sniffs/Formidable/Sniffs/Security/AddDirectFileAccessCheckSniff.php (1)
49-51: Remove unused variable$tokens.The
$tokensvariable is assigned but never used in theprocess()method.♻️ Suggested fix
public function process( File $phpcsFile, $stackPtr ) { - $tokens = $phpcsFile->getTokens(); $filename = $phpcsFile->getFilename();
This should help in a few ways
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.