chore: update to phpstan 2 - #42
Conversation
📝 WalkthroughWalkthroughThe changes update development dependencies, enhance input validation and error handling, refactor file path handling to use dynamic or constant-based paths, and standardize variable naming. Several PHP files now check for required constants or validate inputs before proceeding. Absolute paths are replaced with relative or constant-based paths, improving maintainability and flexibility. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant PHP Script
participant CommonPHP
participant PluginRootConstant
User->>PHP Script: Request page or action
PHP Script->>PluginRootConstant: Check if PLUGIN_ROOT defined
alt PLUGIN_ROOT not defined
PHP Script->>User: Throw RuntimeException
else PLUGIN_ROOT defined
PHP Script->>CommonPHP: require_once common.php
CommonPHP-->>PHP Script: Load dependencies
PHP Script->>User: Continue processing
end
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ Finishing Touches
🧪 Generate Unit Tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/usr/local/emhttp/plugins/tailscale/include/get_log.php (1)
26-28: Good addition of input validationAdding validation for user input before processing improves security by preventing potential code injection or unexpected behavior. Consider making the error message more specific to help with debugging (e.g., "Invalid log file or max lines parameter").
- throw new InvalidArgumentException("Invalid input"); + throw new InvalidArgumentException("Invalid input: log must be a string and max must be numeric");
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
composer.lockis excluded by!**/*.lock
📒 Files selected for processing (14)
composer.json(1 hunks)phpstan.neon(1 hunks)src/usr/local/emhttp/plugins/tailscale/Tailscale_dashboard.page(1 hunks)src/usr/local/emhttp/plugins/tailscale/include/Pages/Dashboard.php(0 hunks)src/usr/local/emhttp/plugins/tailscale/include/Pages/Lock.php(1 hunks)src/usr/local/emhttp/plugins/tailscale/include/Tailscale/LocalAPI.php(1 hunks)src/usr/local/emhttp/plugins/tailscale/include/Tailscale/Translator.php(1 hunks)src/usr/local/emhttp/plugins/tailscale/include/Tailscale/Utils.php(4 hunks)src/usr/local/emhttp/plugins/tailscale/include/common.php(1 hunks)src/usr/local/emhttp/plugins/tailscale/include/data/Config.php(1 hunks)src/usr/local/emhttp/plugins/tailscale/include/data/Lock.php(1 hunks)src/usr/local/emhttp/plugins/tailscale/include/data/Status.php(1 hunks)src/usr/local/emhttp/plugins/tailscale/include/get_log.php(1 hunks)src/usr/local/emhttp/plugins/tailscale/include/page.php(1 hunks)
💤 Files with no reviewable changes (1)
- src/usr/local/emhttp/plugins/tailscale/include/Pages/Dashboard.php
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/usr/local/emhttp/plugins/tailscale/include/Tailscale/Translator.php (1)
src/usr/local/emhttp/plugins/tailscale/include/Tailscale/Info.php (1)
tr(45-48)
🔇 Additional comments (23)
phpstan.neon (1)
2-2: Set PHPStan analysis level to 9
Switching from the"max"keyword to the numeric level9aligns with PHPStan 2’s configuration. Please run your full static analysis (vendor/bin/phpstan analyse) to confirm no new errors are introduced, and update anyignoreErrorsor baseline files if needed.composer.json (1)
3-4: Upgrade dev dependencies for static analysis and code style
Thephpstan/phpstanconstraint is bumped to^2.1andfriendsofphp/php-cs-fixerto^3.75. After runningcomposer update --dev, verify that your CI pipelines and local checks pass, review each tool’s changelog for breaking changes, and adjust any custom configurations accordingly.src/usr/local/emhttp/plugins/tailscale/include/page.php (1)
11-11: Improved file inclusion using relative pathUsing
dirname(__FILE__)ensures that the common.php file is included relative to the current file location rather than using an absolute path. This change improves maintainability as it will work regardless of the installation directory.src/usr/local/emhttp/plugins/tailscale/include/data/Status.php (1)
6-6: Improved file inclusion using relative pathUsing
dirname(dirname(__FILE__))to navigate up two directory levels from the current file is the correct approach for including common.php. This change improves maintainability by removing hardcoded absolute paths.src/usr/local/emhttp/plugins/tailscale/Tailscale_dashboard.page (1)
7-9: Improved document root handlingThe code now dynamically determines the document root with proper fallback mechanisms. This approach is more robust than using hardcoded paths, as it can adapt to different server configurations while maintaining backward compatibility.
src/usr/local/emhttp/plugins/tailscale/include/data/Config.php (1)
6-6: Good improvement to path handlingReplacing the hardcoded absolute path with a dynamically constructed relative path makes the code more portable and less dependent on fixed directory structures.
src/usr/local/emhttp/plugins/tailscale/include/data/Lock.php (1)
6-6: Good improvement to path handlingReplacing the hardcoded absolute path with a dynamically constructed relative path improves maintainability and portability.
src/usr/local/emhttp/plugins/tailscale/include/common.php (2)
5-5: Good addition of centralized constantDefining the
PLUGIN_ROOTconstant within the namespace centralizes the plugin root directory path, which can be reused throughout the codebase.
7-7: Improved path resolution using constantUsing the newly defined
PLUGIN_ROOTconstant in the glob pattern ensures consistent path resolution and improves maintainability.src/usr/local/emhttp/plugins/tailscale/include/Pages/Lock.php (2)
13-15: Good runtime validation of required constantAdding a runtime check for the
PLUGIN_ROOTconstant with a clear exception message improves error handling and helps with debugging.
23-23: Consistent use of centralized constantReplacing hardcoded paths with the
PLUGIN_ROOTconstant across all require statements ensures consistency and makes path management more maintainable.Also applies to: 26-26, 29-29, 32-32
src/usr/local/emhttp/plugins/tailscale/include/Tailscale/Utils.php (4)
25-33: Good addition of input validation!Adding validation for the URL parameter and JSON encoding outcome improves the robustness of the code. This change prevents silent failures and provides clear error messages when issues occur.
136-138: Good defensive coding practice.Similar to the changes in
send_usage(), adding URL validation here ensures the method fails early with a clear error message rather than proceeding with an invalid URL.
181-185: Improved document root handling.This change appropriately handles the document root by:
- Using
$_SERVER['DOCUMENT_ROOT']as the primary source- Providing a fallback value if it's not available
- Adding type checking to ensure
$docrootis a stringThis is more robust than relying on a global variable.
229-229: Enhanced type safety.Adding a type check for
$_SERVER['PHP_SELF']before using it withbasename()prevents potential errors if the server variable isn't set or isn't a string.src/usr/local/emhttp/plugins/tailscale/include/Tailscale/LocalAPI.php (4)
14-14: Good use of class constant.Converting
tailscaleSocketfrom a property to a class constant is appropriate since this is a fixed value that shouldn't change during the object's lifetime.
18-26: Improved input validation and error handling.Similar to the changes in Utils.php, adding validation for the URL parameter and JSON encoding outcome enhances the robustness of the code. This makes the code more reliable by ensuring valid inputs and providing clear error messages.
33-33: Consistent use of class constant.Updated to use the class constant syntax for
tailscaleSocket, maintaining consistency with the earlier change to make it a constant.
39-40: Performance improvement by avoiding redundant JSON encoding.Now the JSON is encoded once at the beginning and the encoded string is reused, which is more efficient and consistent than encoding multiple times.
Also applies to: 46-47
src/usr/local/emhttp/plugins/tailscale/include/Tailscale/Translator.php (4)
7-8: Improved property naming and type documentation.The property was renamed from
$tailscale_langto the more concise$lang, and a PHPDoc type annotation was added to improve type documentation. This makes the code more readable and helps with static analysis.
14-16: Good dependency verification.This runtime check ensures that the required
PLUGIN_ROOTconstant is defined. This is a good practice as it makes the code fail early with a clear error message if a dependency is missing, rather than failing later with a potentially less clear error.
20-22: Better path management using constants.Replacing hardcoded paths with the
PLUGIN_ROOTconstant improves maintainability and reduces the risk of path-related errors if the plugin structure changes.Also applies to: 23-26
28-37: Consistent variable naming throughout the class.The variable renaming from
$tailscale_langto$langis consistently applied throughout the class, including in the recursive flattening logic, property assignment, and thetr()method. This consistency makes the code easier to understand and maintain.Also applies to: 40-40, 45-45
|
Warning Docstrings generation is only available on the Pro tier. |
Summary by CodeRabbit
Bug Fixes
Refactor
Chores