Passed
Push — master ( e7acbe...c65cd9 )
by Esteban De La Fuente
19:00
created

SenderWorker   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 19
c 1
b 0
f 0
dl 0
loc 39
ccs 0
cts 12
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A send() 0 18 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * LibreDTE: Biblioteca PHP (Núcleo).
7
 * Copyright (C) LibreDTE <https://www.libredte.cl>
8
 *
9
 * Este programa es software libre: usted puede redistribuirlo y/o modificarlo
10
 * bajo los términos de la Licencia Pública General Affero de GNU publicada por
11
 * la Fundación para el Software Libre, ya sea la versión 3 de la Licencia, o
12
 * (a su elección) cualquier versión posterior de la misma.
13
 *
14
 * Este programa se distribuye con la esperanza de que sea útil, pero SIN
15
 * GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD
16
 * PARA UN PROPÓSITO DETERMINADO. Consulte los detalles de la Licencia Pública
17
 * General Affero de GNU para obtener una información más detallada.
18
 *
19
 * Debería haber recibido una copia de la Licencia Pública General Affero de
20
 * GNU junto a este programa.
21
 *
22
 * En caso contrario, consulte <http://www.gnu.org/licenses/agpl.html>.
23
 */
24
25
namespace libredte\lib\Core\Package\Billing\Component\Exchange\Worker;
26
27
use libredte\lib\Core\Package\Billing\Component\Exchange\Abstract\AbstractExchangeWorker;
28
use libredte\lib\Core\Package\Billing\Component\Exchange\Contract\ExchangeBagInterface;
29
use libredte\lib\Core\Package\Billing\Component\Exchange\Contract\SenderStrategyInterface;
30
use libredte\lib\Core\Package\Billing\Component\Exchange\Contract\SenderWorkerInterface;
31
use libredte\lib\Core\Package\Billing\Component\Exchange\Exception\ExchangeException;
32
use Throwable;
33
34
/**
35
 * Worker "billing.exchange.sender".
36
 */
37
class SenderWorker extends AbstractExchangeWorker implements SenderWorkerInterface
38
{
39
    /**
40
     * Esquema de las opciones.
41
     *
42
     * @var array<string,array|bool>
43
     */
44
    protected array $optionsSchema = [
45
        'strategy' => [
46
            'types' => 'string',
47
            'default' => 'email.smtp',
48
        ],
49
        'transport' => [
50
            'types' => 'array',
51
            'default' => [],
52
        ],
53
    ];
54
55
    /**
56
     * {@inheritDoc}
57
     */
58
    public function send(ExchangeBagInterface $bag): array
59
    {
60
        $options = $this->resolveOptions($bag->getOptions()->all());
61
        $bag->setOptions($options);
62
        $strategy = $this->getStrategy($options->get('strategy'));
63
64
        assert($strategy instanceof SenderStrategyInterface);
65
66
        try {
67
            $results = $strategy->send($bag);
68
        } catch (Throwable $e) {
69
            throw new ExchangeException(
70
                message: $e->getMessage(),
71
                previous: $e
72
            );
73
        }
74
75
        return $results;
76
    }
77
}
78