/**
* Go through all of the implementations of type, and find other interaces
* that they implement. If those interfaces include `field` as a valid field,
* return them, sorted by how often the implementations include the other
* interface.
*/
static function getSiblingInterfacesIncludingField(Schema $schema, AbstractType $type, $fieldName)
{
$types = $schema->getPossibleTypes($type);
$suggestedInterfaces = array_reduce($types, function ($acc, $t) use($fieldName) {
foreach ($t->getInterfaces() as $i) {
if (empty($i->getFields()[$fieldName])) {
continue;
}
if (!isset($acc[$i->name])) {
$acc[$i->name] = 0;
}
$acc[$i->name] += 1;
}
return $acc;
}, []);
$suggestedInterfaceNames = array_keys($suggestedInterfaces);
usort($suggestedInterfaceNames, function ($a, $b) use($suggestedInterfaces) {
return $suggestedInterfaces[$b] - $suggestedInterfaces[$a];
});
return $suggestedInterfaceNames;
}