-
Notifications
You must be signed in to change notification settings - Fork 31
fix(lib): correctly mark $allowed_item_values type as nullable array
#375
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,7 +121,7 @@ protected function validate_required_array_class_constants( array $required_arra | |
| * | ||
| * @throws Exception | ||
| */ | ||
| protected function validate_required_array_class_constant( $required_array_constant_name, array $allowed_item_values = null ) { | ||
| protected function validate_required_array_class_constant( $required_array_constant_name, ?array $allowed_item_values = null ) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: This nullable type declaration requires PHP 7.1+, but the plugin declares support for PHP 5.6; on supported 5.6 installs this file will fail to parse and can break plugin loading before runtime version checks execute. Keep the parameter untyped (or use a PHP-5.6-compatible approach) to preserve the documented minimum PHP compatibility. [api mismatch] Severity Level: Critical 🚨- ❌ Plugin crashes on PHP 5.6 during addon autoload.
- ❌ Cookiebot_WP PHP version guard never runs on 5.6.
- ⚠️ WordPress admin cannot safely deactivate failing plugin.Steps of Reproduction ✅1. Confirm the plugin advertises PHP 5.6 support: `readme.txt` lines 4–7 show “* Requires
PHP: 5.6”, and `src/lib/Cookiebot_WP.php` defines `const COOKIEBOT_MIN_PHP_VERSION =
'5.6.0';` around lines 5–6 (verified via Grep).
2. On a WordPress site running PHP 5.6, install and activate this plugin so WordPress
loads `cookiebot.php` (lines 1–24) which defines plugin constants, then `require_once`
includes `vendor/autoload.php`, `src/lib/helper.php`, and
`src/lib/global-deprecations.php`, and finally calls `\cybot\cookiebot\lib\cookiebot()` at
`cookiebot.php:26`.
3. In `src/lib/helper.php`, the namespaced `cookiebot()` function (around lines 10–18 and
620–637) returns `Cookiebot_WP::instance()`, whose constructor in
`src/lib/Cookiebot_WP.php` immediately calls
`throw_exception_if_php_version_is_incompatible()` and then `cookiebot_init()`, where
`Cookiebot_Addons::instance()` is invoked (seen in `src/lib/Cookiebot_WP.php` around lines
25–37).
4. `Cookiebot_Addons::__construct()` in `src/addons/Cookiebot_Addons.php` (lines 60–94 and
120–140) builds a container that instantiates `Settings_Service`
(`src/lib/Settings_Service.php:5`), which `use`s
`cybot\cookiebot\addons\controller\addons\Base_Cookiebot_Addon`; Composer’s PSR-4
autoloader then loads `src/addons/controller/addons/Base_Cookiebot_Addon.php`, which in
turn `use`s `cybot\cookiebot\lib\traits\Class_Constant_Override_Validator_Trait` and
`use`s the trait at line 19, triggering inclusion of
`src/lib/traits/Class_Constant_Override_Validator_Trait.php` where
`validate_required_array_class_constant( $required_array_constant_name, ?array
$allowed_item_values = null )` is declared (line 25 in the snippet). On PHP 5.6 this
nullable `?array` parameter is invalid syntax, causing a fatal “unexpected '?'” parse
error at load time before `Cookiebot_WP::throw_exception_if_php_version_is_incompatible()`
can run, breaking plugin initialization on an environment the plugin claims to support.(Use Cmd/Ctrl + Click for best experience) Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** src/lib/traits/Class_Constant_Override_Validator_Trait.php
**Line:** 124:124
**Comment:**
*Api Mismatch: This nullable type declaration requires PHP 7.1+, but the plugin declares support for PHP 5.6; on supported 5.6 installs this file will fail to parse and can break plugin loading before runtime version checks execute. Keep the parameter untyped (or use a PHP-5.6-compatible approach) to preserve the documented minimum PHP compatibility.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix |
||
| if ( ! is_string( $required_array_constant_name ) ) { | ||
| throw new InvalidArgumentException(); | ||
| } | ||
|
|
||
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.
1. Php <7.1 parse error
🐞 Bug☼ ReliabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools