Skip to content

Commit 7a5709a

Browse files
authored
Refactor filterPrimitives method to improve class string handling (#395)
* Refactor filterPrimitives method to improve class string handling and merging logic Signed-off-by: Pushpak Chhajed <pushpak1300@gmail.com> * Refactor Signed-off-by: Pushpak Chhajed <pushpak1300@gmail.com> --------- Signed-off-by: Pushpak Chhajed <pushpak1300@gmail.com>
1 parent a76bfc5 commit 7a5709a

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Mcp/Boost.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,20 @@ private function discoverThirdPartyPrimitives(string $primitiveType): array
165165
*/
166166
private function filterPrimitives(array $availablePrimitives, string $type): array
167167
{
168-
return collect($availablePrimitives)
169-
->diff(config("boost.mcp.{$type}.exclude", []))
170-
->merge(
171-
collect(config("boost.mcp.{$type}.include", []))
172-
->filter(fn (string $class): bool => class_exists($class))
173-
)
168+
$excludeList = config("boost.mcp.{$type}.exclude", []);
169+
$includeList = config("boost.mcp.{$type}.include", []);
170+
171+
$filtered = collect($availablePrimitives)->reject(function (string|object $item) use ($excludeList): bool {
172+
$className = is_string($item) ? $item : $item::class;
173+
174+
return in_array($className, $excludeList, true);
175+
});
176+
177+
$explicitlyIncluded = collect($includeList)
178+
->filter(fn (string $class): bool => class_exists($class));
179+
180+
return $filtered
181+
->merge($explicitlyIncluded)
174182
->values()
175183
->all();
176184
}

0 commit comments

Comments
 (0)