From 2b56e5d516ad5301fefd49641163736ceb0ae706 Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Tue, 8 Nov 2022 09:56:05 +0100 Subject: [PATCH] Postpone exception throwing --- CHANGELOG.md | 6 ++++++ src/JsonPatch.php | 16 +++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e6ea4f..9934c7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.10.2] - 2022-11-08 + +### Added +- Exceptions improved, [#60](https://github.com/swaggest/json-diff/pull/59). + ## [3.10.1] - 2022-10-24 ### Added @@ -85,6 +90,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Compatibility option to `TOLERATE_ASSOCIATIVE_ARRAYS` that mimic JSON objects. +[3.10.2]: https://github.com/swaggest/json-diff/compare/v3.10.1...v3.10.2 [3.10.1]: https://github.com/swaggest/json-diff/compare/v3.10.0...v3.10.1 [3.10.0]: https://github.com/swaggest/json-diff/compare/v3.9.0...v3.10.0 [3.9.0]: https://github.com/swaggest/json-diff/compare/v3.8.3...v3.9.0 diff --git a/src/JsonPatch.php b/src/JsonPatch.php index 1b2d239..7efc8d9 100644 --- a/src/JsonPatch.php +++ b/src/JsonPatch.php @@ -70,13 +70,6 @@ public static function import(array $data) throw new MissingFieldException('path', $operation); } - if (!is_string($operation->op)) { - throw new InvalidFieldTypeException('op', 'string', $operation); - } - if (!is_string($operation->path)) { - throw new InvalidFieldTypeException('path', 'string', $operation); - } - $op = null; switch ($operation->op) { case Add::OP: @@ -98,8 +91,17 @@ public static function import(array $data) $op = new Test(); break; default: + if (!is_string($operation->op)) { + throw new InvalidFieldTypeException('op', 'string', $operation); + } + throw new UnknownOperationException($operation); } + + if (!is_string($operation->path)) { + throw new InvalidFieldTypeException('path', 'string', $operation); + } + $op->path = $operation->path; if ($op instanceof OpPathValue) { if (property_exists($operation, 'value')) {