Skip to content

Commit 36f531a

Browse files
committed
Reflection::toString() appends () after function/method name
1 parent 6439b8b commit 36f531a

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
"tracy/tracy": "^2.3",
2323
"phpstan/phpstan": "^0.12"
2424
},
25+
"conflict": {
26+
"nette/di": "<3.0.6"
27+
},
2528
"suggest": {
2629
"ext-iconv": "to use Strings::webalize(), toAscii(), chr() and reverse()",
2730
"ext-json": "to use Nette\\Utils\\Json",

src/Utils/Reflection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,13 @@ public static function toString(\Reflector $ref): string
246246
if ($ref instanceof \ReflectionClass) {
247247
return $ref->name;
248248
} elseif ($ref instanceof \ReflectionMethod) {
249-
return $ref->getDeclaringClass()->name . '::' . $ref->name;
249+
return $ref->getDeclaringClass()->name . '::' . $ref->name . '()';
250250
} elseif ($ref instanceof \ReflectionFunction) {
251-
return $ref->name;
251+
return $ref->name . '()';
252252
} elseif ($ref instanceof \ReflectionProperty) {
253253
return self::getPropertyDeclaringClass($ref)->name . '::$' . $ref->name;
254254
} elseif ($ref instanceof \ReflectionParameter) {
255-
return '$' . $ref->name . ' in ' . self::toString($ref->getDeclaringFunction()) . '()';
255+
return '$' . $ref->name . ' in ' . self::toString($ref->getDeclaringFunction());
256256
} else {
257257
throw new Nette\InvalidArgumentException;
258258
}

tests/Utils/Reflection.getReturnType.80.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ namespace
121121

122122
Assert::exception(function () {
123123
Reflection::getReturnType(new \ReflectionMethod(NS\A::class, 'unionType'));
124-
}, Nette\InvalidStateException::class, 'The NS\A::unionType is not expected to have a union type.');
124+
}, Nette\InvalidStateException::class, 'The NS\A::unionType() is not expected to have a union type.');
125125

126126
Assert::exception(function () {
127127
Reflection::getReturnType(new \ReflectionMethod(NS\A::class, 'nullableUnionType'));
128-
}, Nette\InvalidStateException::class, 'The NS\A::nullableUnionType is not expected to have a union type.');
128+
}, Nette\InvalidStateException::class, 'The NS\A::nullableUnionType() is not expected to have a union type.');
129129

130130
Assert::same('NS\A', Reflection::getReturnType(new \ReflectionMethod(NS\AExt::class, 'parentTypeExt')));
131131

@@ -139,5 +139,5 @@ namespace
139139

140140
Assert::exception(function () {
141141
Reflection::getReturnType(new \ReflectionFunction('NS\unionType'));
142-
}, Nette\InvalidStateException::class, 'The NS\unionType is not expected to have a union type.');
142+
}, Nette\InvalidStateException::class, 'The NS\unionType() is not expected to have a union type.');
143143
}

tests/Utils/Reflection.toString.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ function func($param)
2929

3030

3131
Assert::same('Foo', Reflection::toString(new ReflectionClass('Foo')));
32-
Assert::same('Foo::method', Reflection::toString(new ReflectionMethod('Foo', 'method')));
32+
Assert::same('Foo::method()', Reflection::toString(new ReflectionMethod('Foo', 'method')));
3333
Assert::same('$param in Foo::method()', Reflection::toString(new ReflectionParameter(['Foo', 'method'], 'param')));
3434
Assert::same('Foo::$var', Reflection::toString(new ReflectionProperty('Foo', 'var')));
35-
Assert::same('func', Reflection::toString(new ReflectionFunction('func')));
35+
Assert::same('func()', Reflection::toString(new ReflectionFunction('func')));
3636
Assert::same('$param in func()', Reflection::toString(new ReflectionParameter('func', 'param')));

0 commit comments

Comments
 (0)