Junior — Senior
Error detection in the presented code
livecode
Task condition
It is necessary to analyze this PHP code fragment, identify possible defects, and suggest ways to improve it. Pay special attention to the correct implementation of dependencies, exception handling, and adherence to clean code principles.
class DbLogger
{
public function logError(string $message)
{
// ..
}
}
class EmailSender
{
private DbLogger $dbLogger;
public function __construct(DbLogger $dbLogger)
{
$this->dbLogger = $dbLogger;
}
public function sendEmail(): void
{
try {
// ...
} catch (SomeException $exception) {
$this->dbLogger->logError($exception->getMessage());
}
}
}