Completed
Push — develop ( 6bec98...3062c0 )
by Carsten
12s
created

FileTransport   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A send() 0 19 2
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2017 Cross Solution <http://cross-solution.de>
8
 */
9
10
namespace Core\Mail;
11
12
use Zend\Mail\Transport\File as BaseFileTransport;
13
use Zend\Mail\Transport\Exception\RuntimeException;
14
15
/**
16
 * A class to handle mail transport during tests
17
 *
18
 * @package Core\Mail
19
 * @author Anthonius Munthi <[email protected]>
20
 * @since 0.30.1
21
 */
22
class FileTransport extends BaseFileTransport
23
{
24
    /**
25
     * Saves e-mail message to a file
26
     *
27
     * @param \Zend\Mail\Message $message
28
     * @throws RuntimeException on not writable target directory or
29
     * on file_put_contents() failure
30
     */
31
    public function send(\Zend\Mail\Message $message)
32
    {
33
        $options  = $this->options;
34
        $filename = call_user_func($options->getCallback(), $this);
35
        $file     = $options->getPath() . DIRECTORY_SEPARATOR . $filename;
36
37
38
        $contents = $message->toString();
39
        $umask = umask();
40
        umask(022);
41
        if (false === file_put_contents($file, $contents, LOCK_EX)) {
42
            throw new RuntimeException(sprintf(
43
                'Unable to write mail to file (directory "%s")',
44
                $options->getPath()
45
            ));
46
        }
47
        umask($umask);
48
        $this->lastFile = $file;
49
    }
50
}
51