From c4f8e2f7b197bd37b8c14b0b29da4f11019fd395 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 22 Feb 2021 18:41:51 -0800 Subject: [PATCH 1/2] Do not call strelen() on null --- src/JsonSchema/Constraints/Constraint.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/JsonSchema/Constraints/Constraint.php b/src/JsonSchema/Constraints/Constraint.php index 389e0f53..fee66e56 100644 --- a/src/JsonSchema/Constraints/Constraint.php +++ b/src/JsonSchema/Constraints/Constraint.php @@ -43,12 +43,15 @@ abstract class Constraint extends BaseConstraint implements ConstraintInterface protected function incrementPath(JsonPointer $path = null, $i) { $path = $path ?: new JsonPointer(''); - $path = $path->withPropertyPaths( - array_merge( - $path->getPropertyPaths(), - array_filter(array($i), 'strlen') - ) - ); + + if ($i !== null && $i !== '') { + $path = $path->withPropertyPaths( + array_merge( + $path->getPropertyPaths(), + array($i) + ) + ); + } return $path; } From 1ad303a9b7d65bfd73c0c54fbc9f5944b98c16ae Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 21 Jul 2021 15:56:22 +0200 Subject: [PATCH 2/2] Switch to do early return --- src/JsonSchema/Constraints/Constraint.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/JsonSchema/Constraints/Constraint.php b/src/JsonSchema/Constraints/Constraint.php index fee66e56..f792da5e 100644 --- a/src/JsonSchema/Constraints/Constraint.php +++ b/src/JsonSchema/Constraints/Constraint.php @@ -44,15 +44,17 @@ protected function incrementPath(JsonPointer $path = null, $i) { $path = $path ?: new JsonPointer(''); - if ($i !== null && $i !== '') { - $path = $path->withPropertyPaths( - array_merge( - $path->getPropertyPaths(), - array($i) - ) - ); + if ($i === null || $i === '') { + return $path; } + $path = $path->withPropertyPaths( + array_merge( + $path->getPropertyPaths(), + array($i) + ) + ); + return $path; }