Skip to content

Commit cb3f8e3

Browse files
committed
uses nette/utils 3.1.5
1 parent 720e989 commit cb3f8e3

File tree

6 files changed

+18
-21
lines changed

6 files changed

+18
-21
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"nette/php-generator": "^3.3.3",
2222
"nette/robot-loader": "^3.2",
2323
"nette/schema": "^1.1",
24-
"nette/utils": "^3.1.4"
24+
"nette/utils": "^3.1.5"
2525
},
2626
"require-dev": {
2727
"nette/tester": "^2.2",

src/DI/Definitions/FactoryDefinition.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Nette;
1313
use Nette\DI\ServiceCreationException;
1414
use Nette\Utils\Reflection;
15+
use Nette\Utils\Type;
1516

1617

1718
/**
@@ -242,13 +243,11 @@ private function completeParameters(Nette\DI\Resolver $resolver): void
242243
}
243244

244245
foreach ($method->getParameters() as $param) {
245-
$methodHint = Reflection::getParameterTypes($param);
246+
$methodType = Type::fromReflection($param);
246247
if (isset($ctorParams[$param->name])) {
247248
$ctorParam = $ctorParams[$param->name];
248-
$ctorHint = Reflection::getParameterTypes($ctorParam);
249-
if ($methodHint !== $ctorHint
250-
&& !is_a((string) reset($methodHint), (string) reset($ctorHint), true)
251-
) {
249+
$ctorType = Type::fromReflection($ctorParam);
250+
if ($ctorType && !$ctorType->allows((string) $methodType)) {
252251
throw new ServiceCreationException(sprintf(
253252
"Type of \$%s in %s::create() doesn't match type in %s constructor.",
254253
$param->name,
@@ -267,10 +266,7 @@ private function completeParameters(Nette\DI\Resolver $resolver): void
267266
) . ($hint ? ", did you mean \${$hint}?" : '.'));
268267
}
269268

270-
$paramDef = PHP_VERSION_ID < 80000
271-
? ($methodHint && $param->allowsNull() ? '?' : '') . reset($methodHint)
272-
: implode('|', $methodHint);
273-
$paramDef .= ' ' . $param->name;
269+
$paramDef = $methodType . ' ' . $param->name;
274270
if ($param->isDefaultValueAvailable()) {
275271
$this->parameters[$paramDef] = Reflection::getParameterDefaultValue($param);
276272
} else {

src/DI/DependencyChecker.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Nette;
1313
use Nette\Utils\Reflection;
14+
use Nette\Utils\Type;
1415
use ReflectionClass;
1516
use ReflectionMethod;
1617

@@ -121,7 +122,7 @@ class_uses($name),
121122
$name,
122123
$prop->name,
123124
$prop->getDocComment(),
124-
Reflection::getPropertyTypes($prop),
125+
(string) Type::fromReflection($prop),
125126
PHP_VERSION_ID >= 80000 ? count($prop->getAttributes(Attributes\Inject::class)) : null,
126127
];
127128
}
@@ -133,7 +134,7 @@ class_uses($name),
133134
$method->name,
134135
$method->getDocComment(),
135136
self::hashParameters($method),
136-
Reflection::getReturnTypes($method),
137+
(string) Type::fromReflection($method),
137138
];
138139
}
139140
}
@@ -157,7 +158,7 @@ class_uses($name),
157158
$uses,
158159
$method->getDocComment(),
159160
self::hashParameters($method),
160-
Reflection::getReturnTypes($method),
161+
(string) Type::fromReflection($method),
161162
];
162163
}
163164

@@ -171,7 +172,7 @@ private static function hashParameters(\ReflectionFunctionAbstract $method): arr
171172
foreach ($method->getParameters() as $param) {
172173
$res[] = [
173174
$param->name,
174-
Reflection::getParameterTypes($param),
175+
(string) Type::fromReflection($param),
175176
$param->isVariadic(),
176177
$param->isDefaultValueAvailable()
177178
? [Reflection::getParameterDefaultValue($param)]

src/DI/Resolver.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,11 @@ private static function autowireArgument(\ReflectionParameter $parameter, callab
569569
));
570570
}
571571

572-
$types = array_diff(Reflection::getParameterTypes($parameter), ['null']);
573-
$type = count($types) === 1 ? reset($types) : null;
572+
$rtype = Nette\Utils\Type::fromReflection($parameter);
573+
$type = $rtype ? $rtype->getSingleName() : null;
574574
$method = $parameter->getDeclaringFunction();
575575

576-
if ($type && !Reflection::isBuiltinType($type)) {
576+
if ($type && !$rtype->isBuiltin()) {
577577
try {
578578
$res = $getter($type, true);
579579
} catch (MissingServiceException $e) {
@@ -607,7 +607,7 @@ private static function autowireArgument(\ReflectionParameter $parameter, callab
607607
return $getter($itemType, false);
608608

609609
} elseif (
610-
($types && $parameter->allowsNull())
610+
($rtype && $parameter->allowsNull())
611611
|| $parameter->isOptional()
612612
|| $parameter->isDefaultValueAvailable()
613613
) {
@@ -621,7 +621,7 @@ private static function autowireArgument(\ReflectionParameter $parameter, callab
621621
throw new ServiceCreationException(sprintf(
622622
'Parameter %s has %s, so its value must be specified.',
623623
$desc,
624-
count($types) > 1 ? 'union type and no default value' : 'no class type or default value'
624+
$rtype && $rtype->isUnion() ? 'union type and no default value' : 'no class type or default value'
625625
));
626626
}
627627
}

tests/DI/Container.dynamic.php80.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ $container = new Container;
1919
Assert::exception(function () use ($container) {
2020
@$container->addService('six', function (): \stdClass|\Closure {}); // @ triggers service should be defined as "imported"
2121
$container->getService('six');
22-
}, Nette\InvalidStateException::class, 'The {closure}%a?% is not expected to have a union type.');
22+
}, Nette\InvalidStateException::class, 'The {closure}%a?% is not expected to have a union%a?% type.');

tests/DI/InjectExtension.getInjectProperties().php80.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class EClass
2828

2929
Assert::exception(function () {
3030
InjectExtension::getInjectProperties(AClass::class);
31-
}, Nette\InvalidStateException::class, 'The AClass::$var is not expected to have a union type.');
31+
}, Nette\InvalidStateException::class, 'The AClass::$var is not expected to have a union%a?% type.');
3232

3333
Assert::same([
3434
'varA' => 'EInjected',

0 commit comments

Comments
 (0)