Mail   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 7
eloc 12
c 2
b 1
f 0
dl 0
loc 67
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A attachFiles() 0 7 3
A __construct() 0 5 1
A attachRaw() 0 4 1
A attachFile() 0 4 1
A mail() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the PHALCON-EXT package.
5
 *
6
 * (c) Jitendra Adhikari <[email protected]>
7
 *     <https://github.com/adhocore>
8
 *
9
 * Licensed under MIT license.
10
 */
11
12
namespace PhalconExt\Mail;
13
14
class Mail extends \Swift_Message
15
{
16
    /** @var Mailer */
17
    protected $mailer;
18
19
    public function __construct(Mailer $mailer)
20
    {
21
        $this->mailer = $mailer;
22
23
        parent::__construct();
24
    }
25
26
    /**
27
     * Attach files.
28
     *
29
     * @param array $filePaths
30
     *
31
     * @return $this
32
     */
33
    public function attachFiles(array $filePaths): self
34
    {
35
        foreach ($filePaths as $alias => $filePath) {
36
            $this->attachFile($filePath, \is_int($alias) ? null : $alias);
37
        }
38
39
        return $this;
40
    }
41
42
    /**
43
     * Attach file.
44
     *
45
     * @param string      $filePath
46
     * @param string|null $alias
47
     *
48
     * @return self
49
     */
50
    public function attachFile(string $filePath, string $alias = null): self
51
    {
52
        return $this->attach(
53
            \Swift_Attachment::fromPath($filePath)->setFilename($alias ?? \basename($filePath))
54
        );
55
    }
56
57
    /**
58
     * Attach raw data.
59
     *
60
     * @param string $data
61
     * @param string $alias
62
     * @param string $type
63
     *
64
     * @return self
65
     */
66
    public function attachRaw(string $data, string $alias, string $type): self
67
    {
68
        return $this->attach(
69
            new \Swift_Attachment($data, $alias, $type)
70
        );
71
    }
72
73
    /**
74
     * Mail the mail with swift mailer.
75
     *
76
     * @return int The count of mailed recipients.
77
     */
78
    public function mail()
79
    {
80
        return $this->mailer->mail($this);
81
    }
82
}
83