Passed
Push — feature/uploadable ( 7c6d25...a7ed20 )
by Daniel
11:07
created

MessageEventListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 16
ccs 7
cts 8
cp 0.875
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 7 2
A __construct() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\EventListener\Mailer;
15
16
use Symfony\Component\Mailer\Event\MessageEvent;
17
use Symfony\Component\Mime\Address;
18
use Symfony\Component\Mime\Email;
19
20
/**
21
 * @author Daniel West <[email protected]>
22
 */
23
class MessageEventListener
24
{
25
    private string $fromEmailAddress;
26
27 5
    public function __construct(string $fromEmailAddress)
28
    {
29 5
        $this->fromEmailAddress = $fromEmailAddress;
30 5
    }
31
32 5
    public function __invoke(MessageEvent $messageEvent): void
33
    {
34 5
        $message = $messageEvent->getMessage();
35 5
        if (!$message instanceof Email) {
36
            return;
37
        }
38 5
        $message->from(Address::fromString($this->fromEmailAddress));
39 5
    }
40
}
41