RetryIfFailedTransport::send()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Transport;
5
6
use Genkgo\Mail\Exception\ConnectionRefusedException;
7
use Genkgo\Mail\MessageInterface;
8
use Genkgo\Mail\TransportInterface;
9
10
final class RetryIfFailedTransport implements TransportInterface
11
{
12
    /**
13
     * @var TransportInterface
14
     */
15
    private $decoratedTransport;
16
17
    /**
18
     * @var int
19
     */
20
    private $retryCount;
21
22
    /**
23
     * @param TransportInterface $transport
24
     * @param int $retryCount
25
     */
26 4
    public function __construct(TransportInterface $transport, int $retryCount)
27
    {
28 4
        $this->decoratedTransport = $transport;
29 4
        $this->retryCount = $retryCount;
30 4
    }
31
32
    /**
33
     * @param MessageInterface $message
34
     * @throws ConnectionRefusedException
35
     */
36 4
    public function send(MessageInterface $message): void
37
    {
38 4
        for ($i = 0; $i < $this->retryCount; $i++) {
39
            try {
40 4
                $this->decoratedTransport->send($message);
41 3
                return;
42 3
            } catch (ConnectionRefusedException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
43
            }
44
        }
45
46 1
        throw new ConnectionRefusedException('Cannot send e-mail, connection failed');
47
    }
48
}
49