Code Duplication    Length = 32-33 lines in 2 locations

lib/classes/Swift/Transport/LoadBalancedTransport.php 1 location

@@ 118-149 (lines=32) @@
115
     *
116
     * @throws Swift_TransportException
117
     */
118
    public function send(Swift_Mime_Message $message, &$failedRecipients = null)
119
    {
120
        $maxTransports = count($this->_transports);
121
        $sent = 0;
122
        $this->_lastUsedTransport = null;
123
124
        for ($i = 0; $i < $maxTransports
125
                     && $transport = $this->_getNextTransport(); ++$i) {
126
            try {
127
                if (!$transport->isStarted()) {
128
                    $transport->start();
129
                }
130
131
                $sent = $transport->send($message, $failedRecipients);
132
                if ($sent) {
133
                    $this->_lastUsedTransport = $transport;
134
                    break;
135
                }
136
137
            } catch (Swift_TransportException $e) {
138
                $this->_killCurrentTransport();
139
            }
140
        }
141
142
        if (count($this->_transports) === 0) {
143
            throw new Swift_TransportException(
144
                'All Transports in LoadBalancedTransport failed, or no Transports available'
145
            );
146
        }
147
148
        return $sent;
149
    }
150
151
    /**
152
     * Register a plugin.

lib/classes/Swift/Transport/FailoverTransport.php 1 location

@@ 45-77 (lines=33) @@
42
     * @return int
43
     * @throws Swift_TransportException
44
     */
45
    public function send(Swift_Mime_Message $message, &$failedRecipients = null)
46
    {
47
        $maxTransports = count($this->_transports);
48
        $sent = 0;
49
        $this->_lastUsedTransport = null;
50
51
        for ($i = 0; $i < $maxTransports
52
                     && $transport = $this->_getNextTransport(); ++$i) {
53
            try {
54
                if (!$transport->isStarted()) {
55
                    $transport->start();
56
                }
57
58
                $sent = $transport->send($message, $failedRecipients);
59
                if ($sent) {
60
                    $this->_lastUsedTransport = $transport;
61
62
                    return $sent;
63
                }
64
65
            } catch (Swift_TransportException $e) {
66
                $this->_killCurrentTransport();
67
            }
68
        }
69
70
        if (count($this->_transports) === 0) {
71
            throw new Swift_TransportException(
72
                'All Transports in FailoverTransport failed, or no Transports available'
73
            );
74
        }
75
76
        return $sent;
77
    }
78
79
    protected function _getNextTransport()
80
    {