Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code style #726

Merged
merged 4 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = [];
vjik marked this conversation as resolved.
Show resolved Hide resolved
foreach ($results as $result) {
$this->errors = array_merge($this->errors, $result->getErrors());
$appendErrors[] = $result->getErrors();
}

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