From ffcc844c851dacf6bbc5ae94815775db60ec2357 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 15 Nov 2026 17:44:58 +0100 Subject: [PATCH] Skip DateTime and DateTimeImmutable arguments, as the parameter often accepts a string or DateTimeInterface too --- internal/aggregate/aggregate.go | 14 ++++++++++++++ internal/aggregate/aggregate_test.go | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/internal/aggregate/aggregate.go b/internal/aggregate/aggregate.go index 3db7b2a6..c55fefd7 100644 --- a/internal/aggregate/aggregate.go +++ b/internal/aggregate/aggregate.go @@ -104,6 +104,12 @@ func resolveGroups(groups map[string]*group) map[string]Resolved { continue } + // a DateTime argument leaves the parameter untyped, as it often accepts a + // string or any DateTimeInterface too + if slices.ContainsFunc(types, isDateTime) { + continue + } + nullable := contains(types, valuetype.Null) members := without(types, valuetype.Null) // only a single type is added, unions are left untyped @@ -172,6 +178,14 @@ func dedupeClasses(types []valuetype.Type) []valuetype.Type { return kept } +func isDateTime(typeName valuetype.Type) bool { + switch phpast.ClassKey(strings.TrimPrefix(typeName.Class(), "\\")) { + case "datetime", "datetimeimmutable": + return true + } + return false +} + // PHP method and function names are case-insensitive, so keys lowercase them. func methodKey(class, method string, position int) string { return phpast.ClassKey(class) + "\x00" + strings.ToLower(method) + "\x00" + strconv.Itoa(position) diff --git a/internal/aggregate/aggregate_test.go b/internal/aggregate/aggregate_test.go index 127aa2df..2a384d59 100644 --- a/internal/aggregate/aggregate_test.go +++ b/internal/aggregate/aggregate_test.go @@ -73,6 +73,19 @@ func TestResolveMethod(t *testing.T) { wantType: "object:App\\Foo", wantFound: true, }, + { + name: "DateTime is skipped", + records: []collect.Record{{Class: "A", Name: "m", Type: valuetype.Object("DateTime")}}, + wantFound: false, + }, + { + name: "DateTimeImmutable with null is skipped", + records: []collect.Record{ + {Class: "A", Name: "m", Type: valuetype.Object("DateTimeImmutable")}, + {Class: "A", Name: "m", Type: "null"}, + }, + wantFound: false, + }, { name: "only unresolved resolves to nothing", records: []collect.Record{{Class: "A", Name: "m"}},