From f5ed86f4fb5b5faa6bc64965b4a0336483841f2a Mon Sep 17 00:00:00 2001 From: filippo.bertilotti <filippobertilotti@gmail.com> Date: Wed, 15 May 2024 12:43:47 +0200 Subject: [PATCH] utilizzo di exception più specifiche per informazioni più specifiche sull'errore (parte 95) --- src/Framework/Container.php | 8 ++++---- src/App/Controllers/products.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/App/Controllers/products.php b/src/App/Controllers/products.php index eb91be1..d7d2159 100644 --- a/src/App/Controllers/products.php +++ b/src/App/Controllers/products.php @@ -3,7 +3,7 @@ use App\Models\Product; use Framework\Viewer; class Products { - public function __construct(private $viewer, private Product $model) { } + public function __construct(private Viewer $viewer, private Product $model) { } public function index() { $products = $this->model->getData(); diff --git a/src/Framework/Container.php b/src/Framework/Container.php index d88e41d..cde3165 100644 --- a/src/Framework/Container.php +++ b/src/Framework/Container.php @@ -4,7 +4,7 @@ use ReflectionClass; use Closure; use ReflectionNamedType; -use Exception; +use InvalidArgumentException; class Container { @@ -30,16 +30,16 @@ $type = $param->getType(); if($type === null) { - throw new Exception("Constructor parameter '{$param->getName()}' in the $class_name class has no type declaration"); + throw new InvalidArgumentException("Constructor parameter '{$param->getName()}' in the $class_name class has no type declaration"); } if( ! ($type instanceof ReflectionNamedType)) { - throw new Exception("Constructor parameter '{$param->getName()}' in the $class_name class is an invalid type: $type + throw new InvalidArgumentException("Constructor parameter '{$param->getName()}' in the $class_name class is an invalid type: $type - only single named type supported"); } if($type->isBuiltin()) { - throw new Exception("Unable to resolve costructor parameter '{$param->getName()}' of type '$type' in the '$class_name' class"); + throw new InvalidArgumentException("Unable to resolve costructor parameter '{$param->getName()}' of type '$type' in the '$class_name' class"); } $dependencies[] = $this->get((string) $type); } -- Gitblit v1.8.0