Skip to content

Commit

Permalink
Refactor simplify logic and change order in condition for exception t…
Browse files Browse the repository at this point in the history
…o avoid potential issues
  • Loading branch information
LadySolveig committed Jul 23, 2024
1 parent d049ca1 commit 574d39d
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions libraries/src/Mail/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,12 @@ public function addAttachment($path, $name = '', $encoding = 'base64', $type = '
$result = true;

if (\is_array($path)) {
if (is_array($name) && !empty($name) && \count($path) != \count($name)) {
if (!empty($name) && \is_array($name) && \count($path) != \count($name)) {
throw new \InvalidArgumentException('The number of attachments must be equal with the number of name');
}

foreach ($path as $key => $file) {
if (isset($name[$key])) {
$result = parent::addAttachment($file, $name[$key], $encoding, $type, $disposition);
} else {
$result = parent::addAttachment($file, basename($file), $encoding, $type, $disposition);
}
$result = parent::addAttachment($file, isset($name[$key]) ? $name[$key] : '', $encoding, $type, $disposition);
}

// Check for boolean false return if exception handling is disabled
Expand Down

0 comments on commit 574d39d

Please sign in to comment.