Passed
Push — master ( 149df4...00100b )
by Petr
09:51
created

Internal::sendEmail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 5
dl 0
loc 8
ccs 3
cts 5
cp 0.6
crap 2.2559
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace kalanis\EmailApi\Services;
4
5
6
use kalanis\EmailApi\Interfaces;
7
use kalanis\EmailApi\Basics;
8
9
10
/**
11
 * Class Internal
12
 * Make and send each mail
13
 */
14
class Internal implements Interfaces\ISending
15
{
16 1
    public function canUseService(): bool
17
    {
18 1
        return true;
19
    }
20
21 1
    public function systemServiceId(): int
22
    {
23 1
        return 1;
24
    }
25
26
    /**
27
     * Send mail directly via php - no hurdles anywhere, no security too
28
     *
29
     * @param Interfaces\IContent $content
30
     * @param Interfaces\IEmailUser $to
31
     * @param Interfaces\IEmailUser $from
32
     * @param Interfaces\IEmailUser $replyTo
33
     * @param bool $toDisabled
34
     * @return Basics\Result
35
     */
36 1
    public function sendEmail(Interfaces\IContent $content, Interfaces\IEmailUser $to, ?Interfaces\IEmailUser $from = null, ?Interfaces\IEmailUser $replyTo = null, $toDisabled = false): Basics\Result
37
    {
38 1
        if (!empty($content->getAttachments())) {
39 1
            return new Basics\Result(false, 'No attachments available for simple mailing');
40
        }
41
        // @codeCoverageIgnoreStart
42
        $result = mail($to->getEmail(), $content->getSubject(), $content->getHtmlBody());
43
        return new Basics\Result(boolval($result), strval($result));
44
        // @codeCoverageIgnoreEnd
45
    }
46
}
47