Skip to content

Commit 9bba8a9

Browse files
committed
removed PHP 5 stuff
1 parent 576704d commit 9bba8a9

File tree

4 files changed

+14
-47
lines changed

4 files changed

+14
-47
lines changed

src/PhpGenerator/Factory.php

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ class Factory
2424
*/
2525
public function fromClassReflection(\ReflectionClass $from)
2626
{
27-
if (PHP_VERSION_ID >= 70000 && $from->isAnonymous()) {
28-
$class = new ClassType;
29-
} else {
30-
$class = new ClassType($from->getShortName(), new PhpNamespace($from->getNamespaceName()));
31-
}
27+
$class = $from->isAnonymous()
28+
? new ClassType
29+
: new ClassType($from->getShortName(), new PhpNamespace($from->getNamespaceName()));
3230
$class->setType($from->isInterface() ? 'interface' : ($from->isTrait() ? 'trait' : 'class'));
3331
$class->setFinal($from->isFinal() && $class->getType() === 'class');
3432
$class->setAbstract($from->isAbstract() && $class->getType() === 'class');
@@ -71,7 +69,7 @@ public function fromMethodReflection(\ReflectionMethod $from)
7169
$method->setReturnReference($from->returnsReference());
7270
$method->setVariadic($from->isVariadic());
7371
$method->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));
74-
if (PHP_VERSION_ID >= 70000 && $from->hasReturnType()) {
72+
if ($from->hasReturnType()) {
7573
$method->setReturnType((string) $from->getReturnType());
7674
$method->setReturnNullable($from->getReturnType()->allowsNull());
7775
}
@@ -91,7 +89,7 @@ public function fromFunctionReflection(\ReflectionFunction $from)
9189
if (!$from->isClosure()) {
9290
$function->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));
9391
}
94-
if (PHP_VERSION_ID >= 70000 && $from->hasReturnType()) {
92+
if ($from->hasReturnType()) {
9593
$function->setReturnType((string) $from->getReturnType());
9694
$function->setReturnNullable($from->getReturnType()->allowsNull());
9795
}
@@ -106,22 +104,8 @@ public function fromParameterReflection(\ReflectionParameter $from)
106104
{
107105
$param = new Parameter($from->getName());
108106
$param->setReference($from->isPassedByReference());
109-
if (PHP_VERSION_ID >= 70000) {
110-
$param->setTypeHint($from->hasType() ? (string) $from->getType() : NULL);
111-
$param->setNullable($from->hasType() && $from->getType()->allowsNull());
112-
} elseif ($from->isArray() || $from->isCallable()) {
113-
$param->setTypeHint($from->isArray() ? 'array' : 'callable');
114-
} else {
115-
try {
116-
$param->setTypeHint($from->getClass() ? $from->getClass()->getName() : NULL);
117-
} catch (\ReflectionException $e) {
118-
if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
119-
$param->setTypeHint($m[1]);
120-
} else {
121-
throw $e;
122-
}
123-
}
124-
}
107+
$param->setTypeHint($from->hasType() ? (string) $from->getType() : NULL);
108+
$param->setNullable($from->hasType() && $from->getType()->allowsNull());
125109
if ($from->isDefaultValueAvailable()) {
126110
$param->setOptional(TRUE);
127111
$param->setDefaultValue($from->isDefaultValueConstant()
@@ -139,8 +123,7 @@ public function fromParameterReflection(\ReflectionParameter $from)
139123
public function fromPropertyReflection(\ReflectionProperty $from)
140124
{
141125
$prop = new Property($from->getName());
142-
$defaults = $from->getDeclaringClass()->getDefaultProperties();
143-
$prop->setValue(isset($defaults[$prop->getName()]) ? $defaults[$prop->getName()] : NULL);
126+
$prop->setValue($from->getDeclaringClass()->getDefaultProperties()[$prop->getName()] ?? NULL);
144127
$prop->setStatic($from->isStatic());
145128
$prop->setVisibility($from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : 'public'));
146129
$prop->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));

src/PhpGenerator/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private static function _dump(&$var, $level = 0)
106106

107107
} elseif (is_object($var)) {
108108
$class = get_class($var);
109-
if (PHP_VERSION_ID >= 70000 && (new \ReflectionObject($var))->isAnonymous()) {
109+
if ((new \ReflectionObject($var))->isAnonymous()) {
110110
throw new Nette\InvalidArgumentException('Cannot dump anonymous class.');
111111

112112
} elseif (in_array($class, ['DateTime', 'DateTimeImmutable'], TRUE)) {

tests/PhpGenerator/Factory.php7.phpt

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/PhpGenerator/Factory.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ Assert::type(Nette\PhpGenerator\ClassType::class, $res);
2020
Assert::same('stdClass', $res->getName());
2121

2222

23+
$res = $factory->fromClassReflection(new ReflectionClass(new class {}));
24+
Assert::type(Nette\PhpGenerator\ClassType::class, $res);
25+
Assert::null($res->getName());
26+
27+
2328
$res = $factory->fromMethodReflection(new \ReflectionMethod(ReflectionClass::class, 'getName'));
2429
Assert::type(Nette\PhpGenerator\Method::class, $res);
2530
Assert::same('getName', $res->getName());

0 commit comments

Comments
 (0)