Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
php: [ '8.0', '8.1', '8.2', '8.3', '8.4' ]

steps:
- uses: actions/checkout@master
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ or recursively instantiating them with *DependencyResolver* itself.
## Features

- Based on PSR-11
- Supports PHP 8 (8.0, 8.1, 8.2, 8.3 and 8.4) — full support of union type hints, and other modern features.
- PHP 7.1+ compatible
- Supports modern PHP 8 features (up to PHP 8.4) — full support of union type hints, and others.
- Recursive dependencies autowiring
- Semver
- Tests
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"auto-wiring"
],
"require": {
"php": "^7.1|^8.0",
"psr/container": "^1.0|^2.0",
"technically/null-container": "^1.0",
"technically/callable-reflection": "^0.4.0"
"php": "^8.0",
"psr/container": "^2.0",
"technically/null-container": "^2.0",
"technically/callable-reflection": "^0.4.2"
},
"require-dev": {
"peridot-php/peridot": "^1.19",
"technically/array-container": "^1.0"
"technically/array-container": "^2.0"
},
"license": "MIT",
"authors": [
Expand Down
16 changes: 7 additions & 9 deletions src/DependencyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

final class DependencyResolver
{
/**
* @var ContainerInterface
*/
private $container;
private ContainerInterface $container;

public function __construct(?ContainerInterface $container = null)
{
Expand All @@ -28,14 +25,14 @@ public function __construct(?ContainerInterface $container = null)

/**
* @param string $className
* @return mixed|object|void
* @return mixed
*
* @throws InvalidArgumentException If class does not exist.
* @throws ContainerExceptionInterface If error occurs while retrieving the existing entry from the container.
* @throws ClassCannotBeInstantiated If class cannot be instantiated.
* @throws CannotAutowireDependencyArgument If a dependency (of any nesting level) cannot be resolved.
*/
public function resolve(string $className)
public function resolve(string $className): mixed
{
if (! class_exists($className) && ! interface_exists($className)) {
throw new InvalidArgumentException("`{$className}` is not a valid class name.");
Expand All @@ -51,11 +48,12 @@ public function resolve(string $className)
/**
* @param string $className
* @param array $bindings
* @return mixed
*
* @throws ClassCannotBeInstantiated
* @throws CannotAutowireDependencyArgument
*/
public function construct(string $className, array $bindings = [])
public function construct(string $className, array $bindings = []): mixed
{
if (! class_exists($className) && ! interface_exists($className)) {
throw new InvalidArgumentException("`{$className}` is not a valid class name.");
Expand Down Expand Up @@ -84,7 +82,7 @@ public function construct(string $className, array $bindings = [])
* @throws ArgumentCountError
* @throws CannotAutowireArgument
*/
public function call(callable $callable, array $bindings = [])
public function call(callable $callable, array $bindings = []): mixed
{
$reflection = CallableReflection::fromCallable($callable);

Expand Down Expand Up @@ -130,7 +128,7 @@ private function resolveParameters(array $parameters, array $bindings = []): arr
*
* @throws CannotAutowireArgument
*/
private function resolveParameter(ParameterReflection $parameter)
private function resolveParameter(ParameterReflection $parameter): mixed
{
foreach ($parameter->getTypes() as $type) {
if ($type->isClassRequirement() && $this->container->has($class = $type->getClassRequirement())) {
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/CannotAutowireArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class CannotAutowireArgument extends DependencyResolutionException
/**
* @var string
*/
private $argumentName;
private string $argumentName;

/**
* @param string $argumentName
Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/CannotAutowireDependencyArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ final class CannotAutowireDependencyArgument extends DependencyResolutionExcepti
/**
* @var string
*/
private $dependencyName;
private string $dependencyName;

/**
* @var string
*/
private $argumentName;
private string $argumentName;

/**
* @param string $dependencyName
Expand Down
6 changes: 3 additions & 3 deletions src/Exceptions/ClassCannotBeInstantiated.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
final class ClassCannotBeInstantiated extends DependencyResolutionException
{
/**
* @var string
* @var class-string
*/
private $className;
private string $className;

public function __construct(string $className)
{
Expand All @@ -17,7 +17,7 @@ public function __construct(string $className)
}

/**
* @return string
* @return class-string
*/
public function getClassName(): string
{
Expand Down