MessageHelper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 46
ccs 18
cts 18
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRecipients() 0 15 2
A getRecipientsDomains() 0 9 1
1
<?php
2
3
namespace ElfSundae\Multimail;
4
5
class MessageHelper
6
{
7
    /**
8
     * Get all recipients for the given message, including To, Reply-To,
9
     * Cc and Bcc addresses.
10
     *
11
     * When the `$associated` is true, this method will return an associative
12
     * array, whereby the keys provide the actual email addresses and the values
13
     * provide the display names.
14
     *
15
     * @param  \Swift_Mime_Message|\Illuminate\Mail\Message  $message
16
     * @param  bool  $associated
17
     * @return string[]
18
     */
19 2
    public static function getRecipients($message, $associated = false)
20
    {
21 2
        $recipients = array_merge(
22 2
            (array) $message->getTo(),
23 2
            (array) $message->getReplyTo(),
24 2
            (array) $message->getCc(),
25 2
            (array) $message->getBcc()
26 2
        );
27
28 2
        if (! $associated) {
29 2
            $recipients = array_keys($recipients);
30 2
        }
31
32 2
        return $recipients;
33
    }
34
35
    /**
36
     * Get domains of the email addresses for the message recipients.
37
     *
38
     * @param  \Swift_Mime_Message|\Illuminate\Mail\Message  $message
39
     * @return string[]
40
     */
41 1
    public static function getRecipientsDomains($message)
42
    {
43 1
        return array_values(array_unique(array_map(
44 1
            function ($address) {
45 1
                return strtolower(last(explode('@', $address)));
46 1
            },
47 1
            static::getRecipients($message, false)
48 1
        )));
49
    }
50
}
51