From 16e4e3ec9e10bc4cfc64d8d237165f806ea41154 Mon Sep 17 00:00:00 2001 From: Niki Zakariassen Date: Thu, 15 Jun 2023 08:10:32 +0200 Subject: [PATCH] Made sure the rule does not crash with vendor files --- src/SpatieLaravelData/Rules/ValidTypeRule.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/SpatieLaravelData/Rules/ValidTypeRule.php b/src/SpatieLaravelData/Rules/ValidTypeRule.php index cdceb21..3c213e4 100644 --- a/src/SpatieLaravelData/Rules/ValidTypeRule.php +++ b/src/SpatieLaravelData/Rules/ValidTypeRule.php @@ -60,6 +60,8 @@ public function processNode(Node $node, Scope $scope): array // Flatten from a list of calls pr. file, to just a list of calls. ->flatten(1) ->map(Call::unserialize(...)) + // Make sure the rule does not crash in case a specific data class has not been analyzed - This can happen with data classes in the vendor folder + ->filter(fn (Call $call) => isset($classCollector[$call->target])) // Check each call for errors ->map(fn (Call $call) => $this->compareTypes($call, $castCollector, $classCollector[$call->target])) // Flatten from a list of errors pr. call, to just a list of errors.