feat: add email adapter DSN parsing#125
Conversation
Greptile SummaryThis PR adds a
Confidence Score: 5/5Safe to merge; all findings are non-blocking validation gaps and a style inconsistency in exception types. The DSN parsing and Messenger failover logic are well-structured and correctly handle the main error paths. The two findings —
Important Files Changed
Reviews (2): Last reviewed commit: "feat: add email adapter DSN parsing" | Re-trigger Greptile |
| try { | ||
| return $adapter->send($message); | ||
| } catch (\Exception $e) { | ||
| $errors[] = $adapter->getName() | ||
| .' (adapter ' | ||
| .($index + 1) | ||
| .'): ' | ||
| .$e->getMessage(); | ||
| } |
There was a problem hiding this comment.
The catch block only catches
\Exception, so PHP \Error subclasses (\TypeError, \ValueError, \Error, etc.) thrown by an adapter will propagate uncaught and bypass the failover loop entirely. Catching \Throwable instead ensures all adapter-level failures are handled and the next adapter is tried.
| try { | |
| return $adapter->send($message); | |
| } catch (\Exception $e) { | |
| $errors[] = $adapter->getName() | |
| .' (adapter ' | |
| .($index + 1) | |
| .'): ' | |
| .$e->getMessage(); | |
| } | |
| try { | |
| return $adapter->send($message); | |
| } catch (\Throwable $e) { | |
| $errors[] = $adapter->getName() | |
| .' (adapter ' | |
| .($index + 1) | |
| .'): ' | |
| .$e->getMessage(); | |
| } |
| private static function parseIntOption(mixed $value, string $option): int | ||
| { | ||
| if (\is_int($value)) { | ||
| return $value; | ||
| } | ||
|
|
||
| if (! \is_string($value) || $value === '' || ! \ctype_digit($value)) { | ||
| throw new \InvalidArgumentException('Invalid "'.$option.'" option. Expected integer value.'); | ||
| } | ||
|
|
||
| return (int) $value; | ||
| } |
There was a problem hiding this comment.
parseIntOption skips range validation when the value is already a PHP int. parse_url returns $parts['port'] as a native integer, so a URL like smtp://host:0 or smtp://host:99999 bypasses the ctype_digit check entirely and passes an invalid port directly to the SMTP constructor. The same zero/overflow gap applies to query-string ports since ctype_digit("0") and ctype_digit("99999") both return true. Adding a positive-integer guard closes this for all call sites (port, timeout, timelimit).
| private static function parseIntOption(mixed $value, string $option): int | |
| { | |
| if (\is_int($value)) { | |
| return $value; | |
| } | |
| if (! \is_string($value) || $value === '' || ! \ctype_digit($value)) { | |
| throw new \InvalidArgumentException('Invalid "'.$option.'" option. Expected integer value.'); | |
| } | |
| return (int) $value; | |
| } | |
| private static function parseIntOption(mixed $value, string $option): int | |
| { | |
| if (\is_int($value)) { | |
| if ($value < 0) { | |
| throw new \InvalidArgumentException('Invalid "'.$option.'" option. Expected non-negative integer value.'); | |
| } | |
| return $value; | |
| } | |
| if (! \is_string($value) || $value === '' || ! \ctype_digit($value)) { | |
| throw new \InvalidArgumentException('Invalid "'.$option.'" option. Expected integer value.'); | |
| } | |
| return (int) $value; | |
| } |
Add DSN (Data Source Name) parsing support for email adapters, enabling connection configuration via DSN strings.