Skip to content

Commit 8d12762

Browse files
committed
Upgrade code to rely on PHP8 features
1 parent 067e9fb commit 8d12762

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

src/DependencyResolver.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616

1717
final class DependencyResolver
1818
{
19-
/**
20-
* @var ContainerInterface
21-
*/
22-
private $container;
19+
private ContainerInterface $container;
2320

2421
public function __construct(?ContainerInterface $container = null)
2522
{
@@ -28,14 +25,14 @@ public function __construct(?ContainerInterface $container = null)
2825

2926
/**
3027
* @param string $className
31-
* @return mixed|object|void
28+
* @return mixed
3229
*
3330
* @throws InvalidArgumentException If class does not exist.
3431
* @throws ContainerExceptionInterface If error occurs while retrieving the existing entry from the container.
3532
* @throws ClassCannotBeInstantiated If class cannot be instantiated.
3633
* @throws CannotAutowireDependencyArgument If a dependency (of any nesting level) cannot be resolved.
3734
*/
38-
public function resolve(string $className)
35+
public function resolve(string $className): mixed
3936
{
4037
if (! class_exists($className) && ! interface_exists($className)) {
4138
throw new InvalidArgumentException("`{$className}` is not a valid class name.");
@@ -51,11 +48,12 @@ public function resolve(string $className)
5148
/**
5249
* @param string $className
5350
* @param array $bindings
51+
* @return mixed
5452
*
5553
* @throws ClassCannotBeInstantiated
5654
* @throws CannotAutowireDependencyArgument
5755
*/
58-
public function construct(string $className, array $bindings = [])
56+
public function construct(string $className, array $bindings = []): mixed
5957
{
6058
if (! class_exists($className) && ! interface_exists($className)) {
6159
throw new InvalidArgumentException("`{$className}` is not a valid class name.");
@@ -84,7 +82,7 @@ public function construct(string $className, array $bindings = [])
8482
* @throws ArgumentCountError
8583
* @throws CannotAutowireArgument
8684
*/
87-
public function call(callable $callable, array $bindings = [])
85+
public function call(callable $callable, array $bindings = []): mixed
8886
{
8987
$reflection = CallableReflection::fromCallable($callable);
9088

@@ -130,7 +128,7 @@ private function resolveParameters(array $parameters, array $bindings = []): arr
130128
*
131129
* @throws CannotAutowireArgument
132130
*/
133-
private function resolveParameter(ParameterReflection $parameter)
131+
private function resolveParameter(ParameterReflection $parameter): mixed
134132
{
135133
foreach ($parameter->getTypes() as $type) {
136134
if ($type->isClassRequirement() && $this->container->has($class = $type->getClassRequirement())) {

src/Exceptions/CannotAutowireArgument.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ final class CannotAutowireArgument extends DependencyResolutionException
99
/**
1010
* @var string
1111
*/
12-
private $argumentName;
12+
private string $argumentName;
1313

1414
/**
1515
* @param string $argumentName

src/Exceptions/CannotAutowireDependencyArgument.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ final class CannotAutowireDependencyArgument extends DependencyResolutionExcepti
99
/**
1010
* @var string
1111
*/
12-
private $dependencyName;
12+
private string $dependencyName;
1313

1414
/**
1515
* @var string
1616
*/
17-
private $argumentName;
17+
private string $argumentName;
1818

1919
/**
2020
* @param string $dependencyName

src/Exceptions/ClassCannotBeInstantiated.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
final class ClassCannotBeInstantiated extends DependencyResolutionException
66
{
77
/**
8-
* @var string
8+
* @var class-string
99
*/
10-
private $className;
10+
private string $className;
1111

1212
public function __construct(string $className)
1313
{
@@ -17,7 +17,7 @@ public function __construct(string $className)
1717
}
1818

1919
/**
20-
* @return string
20+
* @return class-string
2121
*/
2222
public function getClassName(): string
2323
{

0 commit comments

Comments
 (0)