Problem/Motivation
I edit my sites in VSCode, and recently noticed it pop up an error on the generateSampleValue function in Plugin/Field/FieldType/PaymentMethod.php. This is defined as a static method, but uses $this. $this is not available in a static method.
Steps to reproduce
View Paymentmethod.php in an editor that does code validation.
Proposed resolution
Either change generateSampleValue to a normal method, or change the code to work as a static method.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3454305.patch | 633 bytes | prabuela |
Issue fork give-3454305
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
prabuela commentedComment #4
prabuela commentedIndex Out of Bounds:
$values[array_rand($values)]:
This method will always generate a valid index within the bounds of the array.
$values[rand(0, count($values))]:
This can potentially generate an index equal to count($values), which is out of bounds and will cause an error.
Performance and Readability:
$values[array_rand($values)]:
This method is more readable and clearly conveys the intent of selecting a random element from the array.
$values[rand(0, count($values))]:
Even if corrected to $values[rand(0, count($values) - 1)], it is less readable and more error-prone.
Correct and Safe Usage:
Preferred Method: $values[array_rand($values)]
This ensures that a valid index is always selected, preventing any potential index out-of-bounds errors.
Please correct me if I am wrong.
Comment #6
matslats commentedok the patch is committed to HEAD