PhpMailTransport   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 7
c 3
b 0
f 2
lcom 1
cbo 4
dl 0
loc 79
ccs 29
cts 29
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 12 1
A getMailVendor() 0 7 2
A setMailVendor() 0 5 1
A getHeadersAsString() 0 14 3
1
<?php
2
3
/**
4
 * This file is part of slick/mail package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Mail\Transport;
11
12
use Slick\Common\Base;
13
use Slick\Mail\Header\HeaderInterface;
14
use Slick\Mail\MessageInterface;
15
use Slick\Mail\Transport\Vendor\Php;
16
17
/**
18
 * PHP mail() transport
19
 *
20
 * @package Slick\Mail\Transport
21
 * @author  Filipe Silva <[email protected]>
22
 */
23
class PhpMailTransport extends Base implements MailTransportInterface
24
{
25
26
    /**
27
     * @var MessageInterface
28
     */
29
    protected $message;
30
31
    /**
32
     * @var Php
33
     */
34
    protected $mailVendor;
35
36
    /**
37
     * Send a e-mail message
38
     *
39
     * @param MessageInterface $message
40
     *
41
     * @return MailTransportInterface
42
     */
43 2
    public function send(MessageInterface $message)
44
    {
45 2
        $this->message = $message;
46 2
        $this->getMailVendor()
47 2
            ->mail(
48 2
                $message->getToAddressList(),
49 2
                $message->getSubject(),
50 2
                $message->getBodyText(),
51 2
                $this->getHeadersAsString()
52 1
            );
53 2
        return $this;
54
    }
55
56
    /**
57
     * Gets the Mail Vendor object
58
     *
59
     * @return Php
60
     */
61 4
    public function getMailVendor()
62
    {
63 4
        if (null == $this->mailVendor) {
64 2
            $this->setMailVendor(new Php());
65 1
        }
66 4
        return $this->mailVendor;
67
    }
68
69
    /**
70
     * Sets the Mail Vendor object
71
     *
72
     * @param Php $mailVendor
73
     *
74
     * @return PhpMailTransport|$this|self
75
     */
76 4
    public function setMailVendor(Php $mailVendor)
77
    {
78 4
        $this->mailVendor = $mailVendor;
79 4
        return $this;
80
    }
81
82
    /**
83
     * Get the headers for all
84
     *
85
     * @return string
86
     */
87 2
    public function getHeadersAsString()
88
    {
89 2
        $eol = HeaderInterface::EOL;
90 2
        $headers = '';
91 2
        $skipHeaders = ['To', 'Subject'];
92 2
        foreach ($this->message->getHeaders() as $header) {
93 2
            if (in_array($header->getName(), $skipHeaders)) {
94 2
                continue;
95
            }
96 2
            $headers .= "{$header}{$eol}";
97 1
        }
98 2
        $headers = trim($headers).$eol.'X-Mailer: PHP/' . phpversion();
99 2
        return $headers;
100
    }
101
}