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

EmailHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
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
}