Mail   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
c 2
b 1
f 0
lcom 1
cbo 4
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 8 2
A sendMail() 0 15 1
1
<?php
2
3
namespace Core\Helpers;
4
5
use Core\Config;
6
use Swift_Mailer;
7
use Swift_Message;
8
use Swift_SmtpTransport;
9
10
class Mail
11
{
12
    private static $instance;
13
14
    /**
15
     * @return Mail
16
     */
17
    public static function getInstance()
18
    {
19
        if (!isset(self::$instance)) {
20
            self::$instance = new self();
21
        }
22
23
        return self::$instance;
24
    }
25
26
    /**
27
     * @param $data
28
     *
29
     * @return int
30
     */
31
    public static function sendMail($data)
32
    {
33
        $transport = Swift_SmtpTransport::newInstance(Config::get('smtp.server'), Config::get('smtp.port'))
34
            ->setUsername(Config::get('smtp.username'))
35
            ->setPassword(Config::get('smtp.password'));
36
37
        $mailer = Swift_Mailer::newInstance($transport);
38
        $message = Swift_Message::newInstance($data['subject'])
39
            ->setFrom([Config::get('smtp.username') => Config::get('framework.title')])
40
            ->setTo([$data['to']])
41
            ->setContentType('text/html')
42
            ->setBody($data['text']);
43
44
        return $mailer->send($message);
45
    }
46
}
47