/**
* @param \ReflectionClass|string
* @return self
*/
public static function from($from)
{
$from = new \ReflectionClass($from instanceof \ReflectionClass ? $from->getName() : $from);
if (PHP_VERSION_ID >= 70000 && $from->isAnonymous()) {
$class = new static('anonymous');
} else {
$class = new static($from->getShortName(), new PhpNamespace($from->getNamespaceName()));
}
$class->type = $from->isInterface() ? 'interface' : (PHP_VERSION_ID >= 50400 && $from->isTrait() ? 'trait' : 'class');
$class->final = $from->isFinal() && $class->type === 'class';
$class->abstract = $from->isAbstract() && $class->type === 'class';
$class->implements = $from->getInterfaceNames();
$class->documents = $from->getDocComment() ? array(preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t"))) : array();
if ($from->getParentClass()) {
$class->extends = $from->getParentClass()->getName();
$class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames());
}
foreach ($from->getProperties() as $prop) {
if ($prop->getDeclaringClass()->getName() === $from->getName()) {
$class->properties[$prop->getName()] = Property::from($prop);
}
}
foreach ($from->getMethods() as $method) {
if ($method->getDeclaringClass()->getName() === $from->getName()) {
$class->methods[$method->getName()] = Method::from($method)->setNamespace($class->namespace);
}
}
return $class;
}