Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The documented accepted parameter type for all methods in the
Ipv6
class isstring
, but no input validation was done on the parameter, which could lead to various PHP errors, most notably a "passing null to non-nullable" deprecation notice on PHP 8.1.This commit adds input validation to all public methods in the class, allowing only for strings and stringable objects.This commit adds input validation to the
uncompress()
method, allowing only for strings and stringable objects.As the other
public
methods calluncompress()
as the first point of action in their flow, this is sufficient to ensure input validation in all cases.As this class was until now only indirectly tested via the
IriTest
class, a newIpv6Test
class is being introduced containing - for now - only perfunctory tests for the input validation.This test class should be expanded to cover the actual logic in the methods at a later date.
Open questions:
As both thecompress()
as well as thecheck_ipv6()
method call theuncompress()
method at the very start of the method logic, it could be argued that adding input validation to those methods is not needed as adding input validation touncompress()
is sufficient.I've chosen to add the (duplicate) input validation anyway as it will make the error message more descriptive by pointing to the actual method which initially received the invalid input.Again: opinions welcome.