Skip to content

Commit

Permalink
Fix #726: Refactor Result::add(): took array_merge() out of the `…
Browse files Browse the repository at this point in the history
…foreach`
  • Loading branch information
lav45 authored Jul 14, 2024
1 parent de36676 commit 02ad73d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Chg #660: Change type of `$skipOnEmpty` argument in rules' constructors from `mixed` to `bool|callable|null`
- Chg #613: Change type of `$escape` argument in `Error::getValuePath()` from `bool|string|null` to `string|null`
(@arogachev)
- Enh #726: Refactor `Result::add()`: took `array_merge()` out of the `foreach` (@lav45)

## 1.4.1 June 11, 2024

Expand Down
14 changes: 3 additions & 11 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function isAttributeValid(string $attribute): bool
return false;
}
}

return true;
}

Expand Down Expand Up @@ -90,7 +89,6 @@ public function getErrorMessagesIndexedByPath(string $separator = '.', ?string $
$stringValuePath = implode($separator, $error->getValuePath($escape));
$errors[$stringValuePath][] = $error->getMessage();
}

return $errors;
}

Expand All @@ -114,7 +112,6 @@ public function getFirstErrorMessagesIndexedByPath(string $separator = '.', ?str
$stringValuePath = implode($separator, $error->getValuePath($escape));
$errors[$stringValuePath] ??= $error->getMessage();
}

return $errors;
}

Expand All @@ -138,7 +135,6 @@ public function getErrorMessagesIndexedByAttribute(): array

$errors[$key][] = $error->getMessage();
}

return $errors;
}

Expand All @@ -162,7 +158,6 @@ public function getFirstErrorMessagesIndexedByAttribute(): array

$errors[$key] ??= $error->getMessage();
}

return $errors;
}

Expand All @@ -184,7 +179,6 @@ public function getAttributeErrors(string $attribute): array
$errors[] = $error;
}
}

return $errors;
}

Expand All @@ -204,7 +198,6 @@ public function getAttributeErrorMessages(string $attribute): array
$errors[] = $error->getMessage();
}
}

return $errors;
}

Expand Down Expand Up @@ -237,7 +230,6 @@ public function getAttributeErrorMessagesIndexedByPath(
$valuePath = implode($separator, array_slice($error->getValuePath($escape), 1));
$errors[$valuePath][] = $error->getMessage();
}

return $errors;
}

Expand Down Expand Up @@ -272,7 +264,6 @@ public function getCommonErrorMessages(): array
public function addError(string $message, array $parameters = [], array $valuePath = []): self
{
$this->errors[] = new Error($message, $parameters, $valuePath);

return $this;
}

Expand Down Expand Up @@ -316,10 +307,11 @@ public function addErrorWithoutPostProcessing(string $message, array $parameters
*/
public function add(self ...$results): self
{
$appendErrors = [];
foreach ($results as $result) {
$this->errors = array_merge($this->errors, $result->getErrors());
$appendErrors[] = $result->getErrors();
}

$this->errors = array_merge($this->errors, ...$appendErrors);
return $this;
}
}

0 comments on commit 02ad73d

Please sign in to comment.