Skip to content

Commit 1730456

Browse files
committed
Factory methods from() are using PhpNamespace
1 parent 225a120 commit 1730456

File tree

2 files changed

+3
-18
lines changed

2 files changed

+3
-18
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,16 @@ class ClassType extends Nette\Object
6666
public static function from($from)
6767
{
6868
$from = $from instanceof \ReflectionClass ? $from : new \ReflectionClass($from);
69-
$class = new static($from->getShortName());
69+
$class = new static($from->getShortName(), new PhpNamespace($from->getNamespaceName()));
7070
$class->type = $from->isInterface() ? 'interface' : (PHP_VERSION_ID >= 50400 && $from->isTrait() ? 'trait' : 'class');
7171
$class->final = $from->isFinal() && $class->type === 'class';
7272
$class->abstract = $from->isAbstract() && $class->type === 'class';
7373
$class->implements = $from->getInterfaceNames();
7474
$class->documents = $from->getDocComment() ? array(preg_replace('#^\s*\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t"))) : array();
75-
$namespace = $from->getNamespaceName();
7675
if ($from->getParentClass()) {
7776
$class->extends = $from->getParentClass()->getName();
78-
if ($namespace) {
79-
$class->extends = Strings::startsWith($class->extends, "$namespace\\") ? substr($class->extends, strlen($namespace) + 1) : '\\' . $class->extends;
80-
}
8177
$class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames());
8278
}
83-
if ($namespace) {
84-
foreach ($class->implements as & $interface) {
85-
$interface = Strings::startsWith($interface, "$namespace\\") ? substr($interface, strlen($namespace) + 1) : '\\' . $interface;
86-
}
87-
}
8879
foreach ($from->getProperties() as $prop) {
8980
if ($prop->getDeclaringClass() == $from) { // intentionally ==
9081
$class->properties[$prop->getName()] = Property::from($prop);

src/PhpGenerator/Parameter.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,17 @@ public static function from(\ReflectionParameter $from)
4444
$param->typeHint = 'callable';
4545
} else {
4646
try {
47-
$param->typeHint = $from->getClass() ? '\\' . $from->getClass()->getName() : NULL;
47+
$param->typeHint = $from->getClass() ? $from->getClass()->getName() : NULL;
4848
} catch (\ReflectionException $e) {
4949
if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
50-
$param->typeHint = '\\' . $m[1];
50+
$param->typeHint = $m[1];
5151
} else {
5252
throw $e;
5353
}
5454
}
5555
}
5656
$param->optional = PHP_VERSION_ID < 50407 ? $from->isOptional() || ($param->typeHint && $from->allowsNull()) : $from->isDefaultValueAvailable();
5757
$param->defaultValue = (PHP_VERSION_ID === 50316 ? $from->isOptional() : $from->isDefaultValueAvailable()) ? $from->getDefaultValue() : NULL;
58-
59-
$namespace = $from->getDeclaringClass() ? $from->getDeclaringClass()->getNamespaceName() : NULL;
60-
$namespace = $namespace ? "\\$namespace\\" : '\\';
61-
if (Nette\Utils\Strings::startsWith($param->typeHint, $namespace)) {
62-
$param->typeHint = substr($param->typeHint, strlen($namespace));
63-
}
6458
return $param;
6559
}
6660

0 commit comments

Comments
 (0)