Skip to content

Commit 9895894

Browse files
committed
Maybe fixed more bugs
1 parent 2505aab commit 9895894

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/SpatieLaravelData/Rules/ValidTypeRule.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,20 @@ private function checkType(array $call, string $key, string $actualType, array $
114114
$validType = collect($typeList)
115115
->reduce(fn (bool $result, string $expectedType) => $result && $this->isTypesMatching($actualIntersectionType, $expectedType), true);
116116

117+
// We found a expected type which matches the current union type, we therefor continue to next union type in the outer loop
117118
if ($validType) {
118-
return null;
119+
continue 2;
119120
}
120121
}
122+
123+
// No valid expected type was found for the union type
124+
return RuleErrorBuilder::message(sprintf('Argument $%s for %s::__construct() expects type [%s] but [%s] was given', $key, $call['target'], $this->expectedUnionTypesToString($expectedTypes), $actualType))
125+
->line($call['method']['line'])
126+
->file($call['method']['file'])
127+
->build();
121128
}
122129

123-
return RuleErrorBuilder::message(sprintf('Argument $%s for %s::__construct() expects type [%s] but [%s] was given', $key, $call['target'], $this->expectedUnionTypesToString($expectedTypes), $actualType))
124-
->line($call['method']['line'])
125-
->file($call['method']['file'])
126-
->build();
130+
return null;
127131
}
128132

129133
/**

0 commit comments

Comments
 (0)