public function resolve(ResolvedClass $resolved)
{
$class = $resolved->getClass();
$pattern = new AbstractFactory($class->getFullname());
$resolver = new TypeResolver();
// we don't look private and non static methods
$collection = (new Collection($class->getMethods()))->where(sprintf('method => method.getVisibility() == "public" and method.getState() == %s', ReflectedMethod::STATE_STATIC));
if (empty($collection)) {
return;
}
/** @var ReflectedMethod $method */
foreach ($collection as $method) {
// method instanciates at least one object
$instanciated = array_unique($method->getInstanciedClasses());
if (empty($instanciated)) {
continue;
}
foreach ($method->getReturns() as $return) {
// returns an object
if ($resolver->isNative($return->getType())) {
continue;
}
// doesn't return itself (avoid singleton)
if (in_array($return->getType(), array('\\self', '\\static', $class->getFullname()))) {
continue;
}
$pattern->setCreated($return->getType());
$resolved->pushPattern($pattern);
return;
}
}
}