Description
incrementPath is a path manipulation helper that is copy-pasted into the RequiredConstraint of every draft (Draft06, Draft07, Draft2019) because those constraints implement ConstraintInterface directly rather than extending Constraint, and therefore don't inherit the incrementPath method available on the base Constraint class.
Affected Files
src/JsonSchema/Constraints/Drafts/Draft06/RequiredConstraint.php
src/JsonSchema/Constraints/Drafts/Draft07/RequiredConstraint.php
src/JsonSchema/Constraints/Drafts/Draft2019/RequiredConstraint.php
The Draft2019 version has a @todo comment acknowledging this:
/**
* @todo refactor as this was only copied from UndefinedConstraint
*/
protected function incrementPath(?JsonPointer $path, $i): JsonPointer
{
$path = $path ?? new JsonPointer('');
if ($i === null || $i === '') {
return $path;
}
return $path->withPropertyPaths(array_merge($path->getPropertyPaths(), [$i]));
}
Suggested Fix
Move incrementPath onto JsonPointer itself as an instance method, since it exclusively operates on a JsonPointer. All three RequiredConstraint files (and any other constraint that needs it) could then call $path->withAppendedPath($i) without needing to duplicate the helper.
Alternatively, a static utility method on JsonPointer or a dedicated path utility class would also centralise the logic without touching the constraint hierarchy.
Description
incrementPathis a path manipulation helper that is copy-pasted into theRequiredConstraintof every draft (Draft06, Draft07, Draft2019) because those constraints implementConstraintInterfacedirectly rather than extendingConstraint, and therefore don't inherit theincrementPathmethod available on the baseConstraintclass.Affected Files
src/JsonSchema/Constraints/Drafts/Draft06/RequiredConstraint.phpsrc/JsonSchema/Constraints/Drafts/Draft07/RequiredConstraint.phpsrc/JsonSchema/Constraints/Drafts/Draft2019/RequiredConstraint.phpThe Draft2019 version has a
@todocomment acknowledging this:Suggested Fix
Move
incrementPathontoJsonPointeritself as an instance method, since it exclusively operates on aJsonPointer. All threeRequiredConstraintfiles (and any other constraint that needs it) could then call$path->withAppendedPath($i)without needing to duplicate the helper.Alternatively, a static utility method on
JsonPointeror a dedicated path utility class would also centralise the logic without touching the constraint hierarchy.