Conditions | 2 |
Paths | 2 |
Total Lines | 27 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | 5 | public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): ?MailerHandler |
|
19 | { |
||
20 | /** @var array $config */ |
||
21 | 5 | $config = $container->get('config'); |
|
22 | |||
23 | 5 | $emailsTo = $config['log']['emails'] ?? []; |
|
24 | 5 | if (!$emailsTo) { |
|
25 | 2 | return null; |
|
26 | } |
||
27 | |||
28 | 3 | $hostname = $config['hostname']; |
|
29 | 3 | $emailFrom = $config['email']['from']; |
|
30 | |||
31 | 3 | $email = new Email(); |
|
32 | 3 | $email->subject("%level_name% on $hostname: %extra.login%: %message%"); |
|
33 | 3 | $email->addFrom(...(array) $emailFrom); |
|
34 | 3 | $email->addTo(...(array) $emailsTo); |
|
35 | |||
36 | /** @var TransportInterface $transport */ |
||
37 | 3 | $transport = $container->get(TransportInterface::class); |
|
38 | /** @var RecordCompleter $recordCompleter */ |
||
39 | 3 | $recordCompleter = $container->get(RecordCompleter::class); |
|
40 | |||
41 | 3 | $mailerHandler = new MailerHandler($transport, $email); |
|
42 | 3 | $mailerHandler->pushProcessor($recordCompleter); |
|
43 | |||
44 | 3 | return $mailerHandler; |
|
45 | } |
||
47 |