Skip to content

Commit 9acbaa4

Browse files
authored
Merge pull request #34 from 4c0n/breaking-out-of-loop-when-start-is-gte-count
Breaking out of loop when start is greater than or equal to total
2 parents 4e82461 + ebf37b1 commit 9acbaa4

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/MailhogClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ public function findAllMessages(int $limit = 50)
6363

6464
$allMessageData = json_decode($response->getBody()->getContents(), true);
6565

66-
if (0 === $allMessageData['count']) {
67-
return; // all done!
68-
}
69-
7066
foreach ($allMessageData['items'] as $messageData) {
7167
yield MessageFactory::fromMailhogResponse($messageData);
7268
}
7369

7470
$start += $limit;
71+
72+
if ($start >= $allMessageData['total']) {
73+
return;
74+
}
7575
}
7676
}
7777

src/Message/Contact.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct(string $emailAddress, ?string $name = null)
2727

2828
public static function fromString(string $contact): Contact
2929
{
30+
$matches = [];
3031
if (preg_match('~^(?P<name>.*?)\s+<(?P<email>\S*?)>$~i', $contact, $matches)) {
3132
return new self($matches['email'], stripslashes(trim($matches['name'])));
3233
}

src/Message/Mime/MimePart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public static function fromMailhogResponse(array $mimePart): MimePart
6060
if (isset($mimePart['Headers']['Content-Disposition'][0]) &&
6161
stripos($mimePart['Headers']['Content-Disposition'][0], 'attachment') === 0
6262
) {
63+
$matches = [];
6364
preg_match('~filename=(?P<filename>.*?)(;|$)~i', $mimePart['Headers']['Content-Disposition'][0], $matches);
6465
$filename = $matches['filename'];
6566
}

0 commit comments

Comments
 (0)