-
-
Notifications
You must be signed in to change notification settings - Fork 263
Update .htaccess rewrite and error handling logic #3803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Enhanced the adjustRewriteBaseHtaccess method to also configure ErrorDocument 404 in addition to RewriteBase. This ensures proper URL routing and error handling by directing 404 errors to the application's error handler.
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
phpmyfaq/src/phpMyFAQ/Setup/EnvironmentConfigurator.php (2)
97-102: Avoid reparsing .htaccess and simplify RewriteBase updateHere you already have the
RewriteBasedirective token from$htaccess->search(...), but then callgetRewriteBase(), which reparses the file just to obtain the current argument and then immediately overwrite it.You can simplify and make this more robust by:
- Dropping the extra parse and
removeArgument(...)call.- Directly setting the new base from
getServerPath().For example:
- $rewriteBase = $htaccess->search('RewriteBase', TOKEN_DIRECTIVE); - if ($rewriteBase) { - $rewriteBase->removeArgument($this->getRewriteBase()); - $rewriteBase->setArguments((array) $this->getServerPath()); - } + $rewriteBase = $htaccess->search('RewriteBase', TOKEN_DIRECTIVE); + if ($rewriteBase) { + $rewriteBase->setArguments([$this->getServerPath()]); + }This avoids redundant IO and keeps all RewriteBase handling within the already‑parsed
$htaccessstructure.
71-79: Docblock looks good; align with formatter/CS toolingThe expanded docblock clearly reflects the new behavior and return type. However, CI reports
mago format --dry-rundifferences for this file; please runmago formatlocally so the docblock and surrounding code match the project’s formatting rules (likely whitespace/blank‑line details).#!/bin/bash # From repo root mago format git diff
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
phpmyfaq/src/phpMyFAQ/Setup/EnvironmentConfigurator.php(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.php
📄 CodeRabbit inference engine (AGENTS.md)
Use PSR-12 coding standards for PHP code
Files:
phpmyfaq/src/phpMyFAQ/Setup/EnvironmentConfigurator.php
**/*.{php,ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{php,ts,tsx,js,jsx}: Use semicolons at the end of each statement
Use single quotes for strings
Follow best practices for localization, such as using placeholders for dynamic content and avoiding hard-coded strings
Files:
phpmyfaq/src/phpMyFAQ/Setup/EnvironmentConfigurator.php
🪛 GitHub Actions: phpMyFAQ Build
phpmyfaq/src/phpMyFAQ/Setup/EnvironmentConfigurator.php
[error] 69-69: mago format --dry-run reported formatting differences. Differences detected between original and formatted file. Command 'mago format --dry-run' failed with exit code 1. Run 'mago format' to auto-fix.
🔇 Additional comments (1)
phpmyfaq/src/phpMyFAQ/Setup/EnvironmentConfigurator.php (1)
104-109: [rewritten comment]
[classification tag]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
phpmyfaq/src/phpMyFAQ/Setup/EnvironmentConfigurator.php (1)
97-102: RewriteBase adjustment works but re-parses .htaccess and can be simplifiedFunctionally this block is fine, but a couple of points are worth tightening up:
- You already have the
$rewriteBasetoken from$htaccess->search(), but you re-parse the same.htaccessfile insidegetRewriteBase(). This is redundant work and another potential failure point.- Since
Directive::setArguments()appends new arguments instead of clearing the existing list, relying onremoveArgument($this->getRewriteBase())only works if the current value exactly matches whatgetRewriteBase()returns and if there’s only a single argument.(github.com)You can avoid both issues by clearing the current arguments directly on the existing token and then adding the new base, for example:
- $rewriteBase = $htaccess->search('RewriteBase', TOKEN_DIRECTIVE); - if ($rewriteBase) { - $rewriteBase->removeArgument($this->getRewriteBase()); - $rewriteBase->setArguments((array) $this->getServerPath()); - } + $rewriteBase = $htaccess->search('RewriteBase', TOKEN_DIRECTIVE); + if ($rewriteBase) { + foreach ($rewriteBase->getArguments() as $argument) { + $rewriteBase->removeArgument((string) $argument); + } + + $rewriteBase->addArgument((string) $this->getServerPath()); + }This keeps everything on the already-parsed token and guarantees a single, correct
RewriteBaseargument.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
phpmyfaq/src/phpMyFAQ/Setup/EnvironmentConfigurator.php(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.php
📄 CodeRabbit inference engine (AGENTS.md)
Use PSR-12 coding standards for PHP code
Files:
phpmyfaq/src/phpMyFAQ/Setup/EnvironmentConfigurator.php
**/*.{php,ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{php,ts,tsx,js,jsx}: Use semicolons at the end of each statement
Use single quotes for strings
Follow best practices for localization, such as using placeholders for dynamic content and avoiding hard-coded strings
Files:
phpmyfaq/src/phpMyFAQ/Setup/EnvironmentConfigurator.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: phpMyFAQ 8.6 Test on ubuntu-latest
- GitHub Check: phpMyFAQ 8.4 Test on ubuntu-latest
- GitHub Check: phpMyFAQ 8.3 Test on ubuntu-latest
- GitHub Check: phpMyFAQ 8.5 Test on ubuntu-latest
🔇 Additional comments (2)
phpmyfaq/src/phpMyFAQ/Setup/EnvironmentConfigurator.php (2)
71-79: Docblock update is clear and consistent with behaviorThe expanded description (RewriteBase + ErrorDocument 404, boolean return, and exception conditions) accurately reflects what the method does and reads well. No changes needed.
104-109: ErrorDocument 404 handling requires verification of htaccess-parser library behaviorThe code at lines 104–109 calls
search('ErrorDocument 404', TOKEN_DIRECTIVE)and thensetArguments(), but several concerns warrant verification:
Search pattern plausibility: The search uses
'ErrorDocument 404'(including the status code) whereas the workingRewriteBasesearch uses only the directive name. If the underlyingsearch()method matches against only the directive name (not including arguments), this pattern would fail to match.Argument handling asymmetry: The
RewriteBasecode explicitly callsremoveArgument()beforesetArguments(), but theErrorDocument 404code does not. This pattern inconsistency suggests potential issues with howsetArguments()handles existing arguments.Missing test coverage: The test suite (
EnvironmentConfiguratorTest) only verifies thatRewriteBaseis updated correctly; it contains no test that confirmsErrorDocument 404is actually modified in the.htaccessfile. This gap makes it impossible to verify the code works as intended.To resolve these concerns, verify the actual behavior of
Tivie\HtaccessParserv0.4.0—specifically:
- How
HtaccessContainer::search()matches patterns (does it use only the directive name or include arguments?)- How
Directive::setArguments()handles existing arguments (does it replace or append?)If the concerns are confirmed, the fix suggested in the review comment (iterating through tokens, finding the 404 directive, and carefully managing arguments) is sound.
Enhanced the adjustRewriteBaseHtaccess method to also configure ErrorDocument 404 in addition to RewriteBase. This ensures proper URL routing and error handling by directing 404 errors to the application's error handler.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.