MailService::sendEmail()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 9
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Bone\Mail\Service;
4
5
use Bone\View\ViewEngine;
6
use Bone\Server\SiteConfig;
7
use Bone\Server\SiteConfigAwareInterface;
8
use Bone\Server\Traits\HasSiteConfigTrait;
9
use Bone\View\Traits\HasViewTrait;
10
use Bone\View\ViewAwareInterface;
11
use Bone\Mail\EmailMessage;
12
13
use Laminas\Mime\Message;
0 ignored issues
show
Bug introduced by
The type Laminas\Mime\Message was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Laminas\Mime\Part;
0 ignored issues
show
Bug introduced by
The type Laminas\Mime\Part was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Symfony\Component\Mailer\Mailer;
16
use Symfony\Component\Mailer\Transport\TransportInterface;
17
18
class MailService implements SiteConfigAwareInterface, ViewAwareInterface
19
{
20
21
    use HasSiteConfigTrait;
22
    use HasViewTrait;
23
24
    private Mailer $mailer;
25
26
    public function setMailer(Mailer $mailer): void
27
    {
28 2
        $this->mailer = $mailer;
29
    }
30 2
31
    private function renderEmail(string $template, array $data): string
32
    {
33
        return $this->view->render($template, $data);
34
    }
35
36
    public function sendEmail(EmailMessage $message): bool
37
    {
38 1
        $config = $this->getSiteConfig();
39
        $message->setFrom($config->getServerEmail(), $config->getCompany());
40 1
        $body = $this->renderEmail($message->getTemplate(), $message->getViewData());
41
        $message->html($body);
42
        $this->mailer->send($message);
43
44
        return true;
45
    }
46
}
47