Completed
Push — 5.x ( 27843f...9372e3 )
by Lars
13:06
created

Swift_MemorySpool   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 55.56%
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 69
ccs 10
cts 18
cp 0.5556
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isStarted() 0 4 1
A start() 0 3 1
A stop() 0 3 1
A queueMessage() 0 7 1
A flushQueue() 0 17 4
1
<?php
2
3
/*
4
 * This file is part of SwiftMailer.
5
 * (c) 2011 Fabien Potencier <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
/**
12
 * Stores Messages in memory.
13
 *
14
 * @author Fabien Potencier
15
 */
16
class Swift_MemorySpool implements Swift_Spool
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
17
{
18
    protected $messages = array();
19
20
    /**
21
     * Tests if this Transport mechanism has started.
22
     *
23
     * @return bool
24
     */
25
    public function isStarted()
26
    {
27
        return true;
28
    }
29
30
    /**
31
     * Starts this Transport mechanism.
32
     */
33
    public function start()
34
    {
35
    }
36
37
    /**
38
     * Stops this Transport mechanism.
39
     */
40
    public function stop()
41
    {
42
    }
43
44
    /**
45
     * Stores a message in the queue.
46
     *
47
     * @param Swift_Mime_Message $message The message to store
48
     *
49
     * @return bool Whether the operation has succeeded
50
     */
51 2
    public function queueMessage(Swift_Mime_Message $message)
52
    {
53
        //clone the message to make sure it is not changed while in the queue
54 2
        $this->messages[] = clone $message;
55
56 2
        return true;
57
    }
58
59
    /**
60
     * Sends messages using the given transport instance.
61
     *
62
     * @param Swift_Transport $transport        A transport instance
63
     * @param string[]        $failedRecipients An array of failures by-reference
64
     *
65
     * @return int The number of sent emails
66
     */
67 2
    public function flushQueue(Swift_Transport $transport, &$failedRecipients = null)
68
    {
69 2
        if (!$this->messages) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->messages of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
70
            return 0;
71
        }
72
73 2
        if (!$transport->isStarted()) {
74
            $transport->start();
75
        }
76
77 2
        $count = 0;
78 2
        while ($message = array_pop($this->messages)) {
79 2
            $count += $transport->send($message, $failedRecipients);
80
        }
81
82 2
        return $count;
83
    }
84
}
85