Skip to content

Commit

Permalink
Merge pull request #61 from swaggest/move-exception
Browse files Browse the repository at this point in the history
Postpone exception throwing
  • Loading branch information
vearutop authored Nov 8, 2022
2 parents daa7f05 + 2b56e5d commit bc55b27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/JsonPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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')) {
Expand Down

0 comments on commit bc55b27

Please sign in to comment.