diff --git a/src/RowInterfaceProvider.php b/src/RowInterfaceProvider.php index 5e56b32..b6dd759 100644 --- a/src/RowInterfaceProvider.php +++ b/src/RowInterfaceProvider.php @@ -10,7 +10,9 @@ use Ray\Di\InjectorInterface; use Ray\Di\ProviderInterface; use Ray\Query\Exception\SqlFileNotFoundException; -use Throwable; + +use function error_log; +use function sprintf; /** @implements ProviderInterface */ final class RowInterfaceProvider implements ProviderInterface @@ -23,6 +25,8 @@ final class RowInterfaceProvider implements ProviderInterface /** @var SqlFinder */ private $finder; + + /** @var InjectorInterface */ private $injector; public function __construct( @@ -41,14 +45,19 @@ public function get(): QueryInterface { try { $sql = ($this->finder)($this->ip->getParameter()); - } catch (SqlFileNotFoundException | Throwable $e) { + // For development + // @codeCoverageIgnoreStart + } catch (SqlFileNotFoundException $e) { try { $named = $e->sql; + $instance = $this->injector->getInstance(RowInterface::class, $named); + error_log(sprintf('Warning: #[Sql(\'%s\')] is not vald. Change to #[\\Ray\\Di\\Di\\Named(\'%s\')]', $named, $named)); - return $this->injector->getInstance(RowInterface::class, $named); + return $instance; } catch (Unbound $unbound) { throw $e; } + // @codeCoverageIgnoreEnd } return new SqlQueryRow($this->pdo, $sql); diff --git a/src/RowListInterfaceProvider.php b/src/RowListInterfaceProvider.php index 11c89f9..2380e9e 100644 --- a/src/RowListInterfaceProvider.php +++ b/src/RowListInterfaceProvider.php @@ -11,6 +11,10 @@ use Ray\Di\ProviderInterface; use Ray\Query\Exception\SqlFileNotFoundException; +use function assert; +use function error_log; +use function sprintf; + /** @implements ProviderInterface */ final class RowListInterfaceProvider implements ProviderInterface { @@ -22,6 +26,8 @@ final class RowListInterfaceProvider implements ProviderInterface /** @var SqlFinder */ private $finder; + + /** @var InjectorInterface */ private $injector; public function __construct( @@ -43,14 +49,28 @@ public function get(): QueryInterface } catch (SqlFileNotFoundException $e) { try { $named = $e->sql; + // Try "RowListInterface" + $instance = $this->injector->getInstance(RowListInterface::class, $named); + // For development + // @codeCoverageIgnoreStart + assert($instance instanceof QueryInterface); + error_log(sprintf('Warning: #[Sql(\'%s\')] is not vald. Change to #[\\Ray\\Di\\Di\\Named(\'%s\')]', $named, $named)); - return $this->injector->getInstance(RowListInterface::class, $named); + return $instance; } catch (Unbound $unbound) { try { - return $this->injector->getInstance('', $named); + assert(isset($named)); // @phpstan-ignore-line + // try "callable" + /** @var QueryInterface $instance */ + $instance = $this->injector->getInstance('', $named); + assert($instance instanceof QueryInterface); + error_log(sprintf('Warning: #[Sql(\'%s\')] is not vald. Change to #[\\Ray\\Di\\Di\\Named(\'%s\')]', $named, $named)); + + return $instance; } catch (Unbound $unbound) { throw $e; } + // @codeCoverageIgnoreEnd } }