Skip to content

Commit

Permalink
Type::merge() merges arrays only according to the schema (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 5, 2024
1 parent 56d3daa commit adb13ea
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Schema/Elements/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class Type implements Schema
private array $range = [null, null];
private ?string $pattern = null;
private bool $merge = false;
private ?MergeMode $mergeMode = null;
private MergeMode $mergeMode = MergeMode::AppendKeys;


public function __construct(string $type)
Expand Down Expand Up @@ -148,7 +148,7 @@ public function merge(mixed $value, mixed $base): mixed
return $value;
}

if (is_array($value) && is_array($base) && ($this->itemsValue || $this->mergeMode)) {
if (is_array($value) && is_array($base)) {
$index = $this->mergeMode === MergeMode::OverwriteKeys ? null : 0;
foreach ($value as $key => $val) {
if ($key === $index) {
Expand All @@ -164,7 +164,7 @@ public function merge(mixed $value, mixed $base): mixed
return $base;
}

return Helpers::merge($value, $base);
return $value === null && is_array($base) ? $base : $value;
}


Expand Down

0 comments on commit adb13ea

Please sign in to comment.