Skip to content

Commit

Permalink
Refactor error handling for SqlFileNotFoundException
Browse files Browse the repository at this point in the history
Moved the error handling for SqlFileNotFoundException into its own private method, handleSqlNotFound, for improved readability and simplicity. This change does not alter the functionality but enhances code structure and maintainability.
  • Loading branch information
koriym committed Jun 13, 2024
1 parent ef267e5 commit 7bd1d67
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/RowInterfaceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,23 @@ public function get(): QueryInterface
// 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 $instance;
} catch (Unbound $unbound) {
throw $e;
}
// @codeCoverageIgnoreEnd
return $this->handleSqlNotFound($e);

Check failure on line 51 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedReturnStatement: Could not infer a return type

Check failure on line 51 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedReturnStatement: Could not infer a return type
}

return new SqlQueryRow($this->pdo, $sql);
}

private function handleSqlNotFound($e)

Check failure on line 57 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Method \Ray\Query\RowInterfaceProvider::handleSqlNotFound() does not have parameter type hint nor @param annotation for its parameter $e.

Check failure on line 57 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Method \Ray\Query\RowInterfaceProvider::handleSqlNotFound() does not have return type hint nor @return annotation for its return value.

Check failure on line 57 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Method Ray\Query\RowInterfaceProvider::handleSqlNotFound() has no return type specified.

Check failure on line 57 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Method Ray\Query\RowInterfaceProvider::handleSqlNotFound() has parameter $e with no type specified.

Check failure on line 57 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MissingReturnType: Method Ray\Query\RowInterfaceProvider::handleSqlNotFound does not have a return type, expecting Ray\Query\RowInterface

Check failure on line 57 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MissingParamType: Parameter $e has no provided type

Check failure on line 57 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Method Ray\Query\RowInterfaceProvider::handleSqlNotFound() has no return type specified.

Check failure on line 57 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Method Ray\Query\RowInterfaceProvider::handleSqlNotFound() has parameter $e with no type specified.

Check failure on line 57 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MissingReturnType: Method Ray\Query\RowInterfaceProvider::handleSqlNotFound does not have a return type, expecting Ray\Query\RowInterface

Check failure on line 57 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MissingParamType: Parameter $e has no provided type

Check failure on line 57 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Method \Ray\Query\RowInterfaceProvider::handleSqlNotFound() does not have parameter type hint nor @param annotation for its parameter $e.

Check failure on line 57 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Method \Ray\Query\RowInterfaceProvider::handleSqlNotFound() does not have return type hint nor @return annotation for its return value.
{
try {
$named = $e->sql;

Check failure on line 60 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedAssignment: Unable to determine the type that $named is being assigned to

Check failure on line 60 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedPropertyFetch: Cannot fetch property on mixed var $e

Check failure on line 60 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedAssignment: Unable to determine the type that $named is being assigned to

Check failure on line 60 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedPropertyFetch: Cannot fetch property on mixed var $e
$instance = $this->injector->getInstance(RowInterface::class, $named);

Check failure on line 61 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedArgument: Argument 2 of Ray\Di\InjectorInterface::getInstance cannot be mixed, expecting string

Check failure on line 61 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedArgument: Argument 2 of Ray\Di\InjectorInterface::getInstance cannot be mixed, expecting string
error_log(sprintf('Warning: #[Sql(\'%s\')] is not vald. Change to #[\\Ray\\Di\\Di\\Named(\'%s\')]', $named, $named));

Check failure on line 62 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedArgument: Argument 2 of sprintf cannot be mixed, expecting float|int|string

Check failure on line 62 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedArgument: Argument 3 of sprintf cannot be mixed, expecting float|int|string

Check failure on line 62 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedArgument: Argument 2 of sprintf cannot be mixed, expecting float|int|string

Check failure on line 62 in src/RowInterfaceProvider.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

MixedArgument: Argument 3 of sprintf cannot be mixed, expecting float|int|string

return $instance;
} catch (Unbound $unbound) {
throw $e;
}
// @codeCoverageIgnoreEnd
}
}

0 comments on commit 7bd1d67

Please sign in to comment.