Driver_Sendmail   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A prepare() 0 19 1
A send() 0 17 1
1
<?php
2
3
/**
4
 * Provides mail functionality using the php mail function
5
 *
6
 * PHP Version 5
7
 *
8
 * @category  Core
9
 * @package   Mail
10
 * @author    Hans-Joachim Piepereit <[email protected]>
11
 * @copyright 2013 cSphere Team
12
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
13
 * @link      http://www.csphere.eu
14
 **/
15
16
namespace csphere\core\mail;
17
18
/**
19
 * Provides mail functionality using the php mail function
20
 *
21
 * @category  Core
22
 * @package   Mail
23
 * @author    Hans-Joachim Piepereit <[email protected]>
24
 * @copyright 2013 cSphere Team
25
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
26
 * @link      http://www.csphere.eu
27
 **/
28
29
class Driver_Sendmail extends Base
30
{
31
    /**
32
     * Creates the mail handler object
33
     *
34
     * @param array $config Configuration details as an array
35
     *
36
     * @return \csphere\core\mail\Driver_Sendmail
37
     **/
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
38
39
    public function __construct(array $config)
40
    {
41
        parent::__construct($config);
42
43
        // Change sendmail setting
44
        ini_set('sendmail_from', $this->config['from']);
45
    }
46
47
    /**
48
     * Prepares a mail by setting its content
49
     *
50
     * @param string $subject Subject to use in email
51
     * @param string $message Message to use in email
52
     * @param string $type    Defaults to text/plain
53
     *
54
     * @return boolean
55
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
56
57
    public function prepare($subject, $message, $type = 'text/plain')
58
    {
59
        // Run initial preparations
60
        parent::prepare($subject, $message, $type);
61
62
        // Set header data
63
        $headers = ['MIME-Version: 1.0',
64
                    'Content-Type: ' . $type . '; charset=UTF-8',
65
                    'Content-Transfer-Encoding: base64',
66
                    'X-Mailer: cSphere',
67
                    'From: ' . $this->config['from']];
68
69
        $this->headers = array_merge($this->headers, $headers);
70
71
        // Create encoded subject and content strings
72
        $this->encode();
73
74
        return true;
75
    }
76
77
    /**
78
     * Sends the prepared content to a given email
79
     *
80
     * @param string  $email Email target
81
     * @param boolean $clear Defaults to true which keeps mail data
82
     *
83
     * @return boolean
84
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
85
86
    public function send($email, $clear = true)
87
    {
88
        // Send mail
89
        $headers = implode($this->config['eol'], $this->headers);
90
91
        $send = mail(
92
            $email, $this->content['subject_b64'],
93
            $this->content['message_b64'], $headers
94
        );
95
96
        // Log mail and handle clear status
97
        $this->log($email, $send);
98
99
        $this->clear($clear);
100
101
        return $send;
102
    }
103
}
104