Skip to content

Commit 0e8ac18

Browse files
committed
Rename Result->isValid method
1 parent 901774f commit 0e8ac18

32 files changed

Lines changed: 71 additions & 59 deletions

library/Message/StandardFormatter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function resultWithPath(Result $parent, Result $child): Result
159159

160160
private function isAlwaysVisible(Result $result, Result ...$siblings): bool
161161
{
162-
if ($result->isValid) {
162+
if ($result->hasPassed) {
163163
return false;
164164
}
165165

@@ -275,11 +275,11 @@ private function extractDeduplicatedChildren(Result $result): array
275275
}
276276

277277
if ($child->path === null) {
278-
$deduplicatedResults[$id] = $child->isValid ? null : $child->withId($id);
278+
$deduplicatedResults[$id] = $child->hasPassed ? null : $child->withId($id);
279279
continue;
280280
}
281281

282-
$deduplicatedResults[$id] = $child->isValid ? null : $child;
282+
$deduplicatedResults[$id] = $child->hasPassed ? null : $child;
283283
}
284284

285285
return array_values(array_filter($deduplicatedResults));

library/Result.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class Result
3131

3232
/** @param array<string, mixed> $parameters */
3333
public function __construct(
34-
public readonly bool $isValid,
34+
public readonly bool $hasPassed,
3535
public readonly mixed $input,
3636
public readonly Rule $rule,
3737
public readonly array $parameters = [],
@@ -77,7 +77,7 @@ public static function fromAdjacent(
7777
string $template = Rule::TEMPLATE_STANDARD
7878
): Result {
7979
if ($adjacent->allowsAdjacent()) {
80-
return (new Result($adjacent->isValid, $input, $rule, $parameters, $template, id: $adjacent->id))
80+
return (new Result($adjacent->hasPassed, $input, $rule, $parameters, $template, id: $adjacent->id))
8181
->withPrefix($prefix)
8282
->withAdjacent($adjacent->withInput($input));
8383
}
@@ -202,7 +202,7 @@ public function withAdjacent(Result $adjacent): self
202202
public function withToggledValidation(): self
203203
{
204204
return $this->clone(
205-
isValid: !$this->isValid,
205+
hasPassed: !$this->hasPassed,
206206
adjacent: $this->adjacent?->withToggledValidation(),
207207
children: array_map(static fn (Result $child) => $child->withToggledValidation(), $this->children),
208208
);
@@ -211,7 +211,7 @@ public function withToggledValidation(): self
211211
public function withToggledModeAndValidation(): self
212212
{
213213
return $this->clone(
214-
isValid: !$this->isValid,
214+
hasPassed: !$this->hasPassed,
215215
mode: !$this->hasInvertedMode,
216216
adjacent: $this->adjacent?->withToggledModeAndValidation(),
217217
children: array_map(static fn (Result $child) => $child->withToggledModeAndValidation(), $this->children),
@@ -242,7 +242,7 @@ public function allowsAdjacent(): bool
242242
* @param array<Result>|null $children
243243
*/
244244
private function clone(
245-
?bool $isValid = null,
245+
?bool $hasPassed = null,
246246
mixed $input = null,
247247
?array $parameters = null,
248248
?string $template = null,
@@ -254,7 +254,7 @@ private function clone(
254254
?array $children = null
255255
): self {
256256
return new self(
257-
$isValid ?? $this->isValid,
257+
$hasPassed ?? $this->hasPassed,
258258
$input ?? $this->input,
259259
$this->rule,
260260
$parameters ?? $this->parameters,

library/Rules/AllOf.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ final class AllOf extends Composite
3939
public function evaluate(mixed $input): Result
4040
{
4141
$children = array_map(static fn (Rule $rule) => $rule->evaluate($input), $this->rules);
42-
$valid = array_reduce($children, static fn (bool $carry, Result $result) => $carry && $result->isValid, true);
43-
$failed = array_filter($children, static fn (Result $result): bool => !$result->isValid);
42+
$valid = array_reduce($children, static fn (bool $carry, Result $result) => $carry && $result->hasPassed, true);
43+
$failed = array_filter($children, static fn (Result $result): bool => !$result->hasPassed);
4444
$template = self::TEMPLATE_SOME;
4545
if (count($children) === count($failed)) {
4646
$template = self::TEMPLATE_ALL;

library/Rules/AnyOf.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ final class AnyOf extends Composite
2828
public function evaluate(mixed $input): Result
2929
{
3030
$children = array_map(static fn (Rule $rule) => $rule->evaluate($input), $this->rules);
31-
$valid = array_reduce($children, static fn (bool $carry, Result $result) => $carry || $result->isValid, false);
31+
$valid = array_reduce(
32+
$children,
33+
static fn (bool $carry, Result $result) => $carry || $result->hasPassed,
34+
false,
35+
);
3236

3337
return (new Result($valid, $input, $this))->withChildren(...$children);
3438
}

library/Rules/Attributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class Attributes extends Standard
2323
public function evaluate(mixed $input): Result
2424
{
2525
$objectType = (new ObjectType())->evaluate($input);
26-
if (!$objectType->isValid) {
26+
if (!$objectType->hasPassed) {
2727
return $objectType->withId('attributes');
2828
}
2929

library/Rules/Circuit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function evaluate(mixed $input): Result
2020
{
2121
foreach ($this->rules as $rule) {
2222
$result = $rule->evaluate($input);
23-
if (!$result->isValid) {
23+
if (!$result->hasPassed) {
2424
return $result;
2525
}
2626
}

library/Rules/Core/Envelope.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ public function __construct(
2323

2424
public function evaluate(mixed $input): Result
2525
{
26-
return new Result($this->rule->evaluate($input)->isValid, $input, $this, $this->parameters);
26+
return new Result($this->rule->evaluate($input)->hasPassed, $input, $this, $this->parameters);
2727
}
2828
}

library/Rules/Core/FilteredNonEmptyArray.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ abstract protected function evaluateNonEmptyArray(array $input): Result;
2424
public function evaluate(mixed $input): Result
2525
{
2626
$iterableResult = (new IterableType())->evaluate($input);
27-
if (!$iterableResult->isValid) {
27+
if (!$iterableResult->hasPassed) {
2828
return $iterableResult->withIdFrom($this)->withNameFrom($this->rule);
2929
}
3030

3131
$array = $this->toArray($input);
3232
$notEmptyResult = (new NotEmpty())->evaluate($array);
33-
if (!$notEmptyResult->isValid) {
33+
if (!$notEmptyResult->hasPassed) {
3434
return $notEmptyResult->withIdFrom($this)->withNameFrom($this->rule);
3535
}
3636

library/Rules/Core/Standard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class Standard implements Rule
1919
*/
2020
public function validate(mixed $input): bool
2121
{
22-
return $this->evaluate($input)->isValid;
22+
return $this->evaluate($input)->hasPassed;
2323
}
2424

2525
/**

library/Rules/CreditCard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function evaluate(mixed $input): Result
7575
}
7676

7777
$filteredInput = (string) preg_replace('/[ .-]/', '', (string) $input);
78-
if (!(new Luhn())->evaluate($filteredInput)->isValid) {
78+
if (!(new Luhn())->evaluate($filteredInput)->hasPassed) {
7979
return Result::failed($input, $this, $parameters, $template);
8080
}
8181

0 commit comments

Comments
 (0)