Passed
Pull Request — multiproject/requestforms (#741)
by Simon
14:49 queued 10:35
created

EmailHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 13
dl 0
loc 34
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A sendMail() 0 15 3
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\Helpers;
10
11
use Waca\Helpers\Interfaces\IEmailHelper;
12
13
class EmailHelper implements IEmailHelper
14
{
15
    /** @var string */
16
    private $emailFrom;
17
    private $instance;
18
19
    public function __construct(string $emailFrom, $instance)
20
    {
21
        $this->emailFrom = $emailFrom;
22
        $this->instance = $instance;
23
    }
24
25
    /**
26
     * @param string|null $replyAddress
27
     * @param string      $to
28
     * @param string      $subject
29
     * @param string      $content
30
     * @param array       $headers Extra headers to include
31
     */
32
    public function sendMail(?string $replyAddress, $to, $subject, $content, $headers = array())
33
    {
34
        if ($replyAddress !== null) {
35
            $headers['Reply-To'] = $replyAddress;
36
        }
37
38
        $headers['From'] = $this->emailFrom;
39
        $headers['X-ACC-Instance'] = $this->instance;
40
        $headerString = '';
41
42
        foreach ($headers as $header => $headerValue) {
43
            $headerString .= $header . ': ' . $headerValue . "\r\n";
44
        }
45
46
        mail($to, $subject, $content, $headerString);
47
    }
48
}