Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions internal/aggregate/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions internal/aggregate/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down
Loading