public function resolve(ResolvedClass $resolved)
{
$class = $resolved->getClass();
$pattern = new Singleton($class->getFullname());
$methods = $class->getMethods();
// private construct ?
if (isset($methods['__construct']) && $methods['__construct']->getVisibility() !== ReflectedMethod::VISIBILITY_PUBLIC) {
// static method ?
foreach ($methods as $method) {
if ($method->getState() === ReflectedMethod::STATE_STATIC) {
// call itself ?
$deps = $method->getReturns();
foreach ($deps as $dep) {
if (in_array($dep->getType(), array('\\self', '\\static', $class->getFullname()))) {
// yes, class is a singleton
$resolved->pushPattern($pattern);
return;
}
}
}
}
}
}