Passed
Push — master ( 57c539...d81008 )
by Esteban De La Fuente
14:52
created

Postman   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 71
ccs 0
cts 14
cp 0
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setOptions() 0 9 2
A getEnvelopes() 0 3 1
A getOptions() 0 3 1
A __construct() 0 3 1
A addEnvelope() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Derafu: Biblioteca PHP (Núcleo).
7
 * Copyright (C) Derafu <https://www.derafu.org>
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 GNU
20
 * junto a este programa.
21
 *
22
 * En caso contrario, consulte <http://www.gnu.org/licenses/agpl.html>.
23
 */
24
25
namespace Derafu\Lib\Core\Package\Prime\Component\Mail\Support;
26
27
use Derafu\Lib\Core\Package\Prime\Component\Mail\Contract\EnvelopeInterface;
28
use Derafu\Lib\Core\Package\Prime\Component\Mail\Contract\PostmanInterface;
29
use Derafu\Lib\Core\Support\Store\Contract\DataContainerInterface;
30
use Derafu\Lib\Core\Support\Store\DataContainer;
31
32
/**
33
 * Clase que representa un sobre con mensajes que se enviarán por correo
34
 * electrónico.
35
 */
36
class Postman implements PostmanInterface
37
{
38
    /**
39
     * Sobres que el cartero transportará.
40
     *
41
     * @var EnvelopeInterface[]
42
     */
43
    private array $envelopes = [];
44
45
    /**
46
     * Opciones del cartero para el transporte de los sobres.
47
     *
48
     * @var DataContainerInterface
49
     */
50
    private DataContainerInterface $options;
51
52
    /**
53
     * Esquema de las opciones del cartero.
54
     *
55
     * @var array
56
     */
57
    private array $optionsSchema = [];
58
59
    /**
60
     * Constructor del cartero.
61
     *
62
     * @param array $options
63
     */
64
    public function __construct(DataContainerInterface|array $options = [])
65
    {
66
        $this->setOptions($options);
67
    }
68
69
    /**
70
     * {@inheritDoc}
71
     */
72
    public function addEnvelope(EnvelopeInterface $envelope): static
73
    {
74
        $this->envelopes[] = $envelope;
75
76
        return $this;
77
    }
78
79
    /**
80
     * {@inheritDoc}
81
     */
82
    public function getEnvelopes(): array
83
    {
84
        return $this->envelopes;
85
    }
86
87
    /**
88
     * {@inheritDoc}
89
     */
90
    public function setOptions(DataContainerInterface|array $options): static
91
    {
92
        if (is_array($options)) {
0 ignored issues
show
introduced by
The condition is_array($options) is always true.
Loading history...
93
            $options = new DataContainer($options, $this->optionsSchema);
94
        }
95
96
        $this->options = $options;
97
98
        return $this;
99
    }
100
101
    /**
102
     * {@inheritDoc}
103
     */
104
    public function getOptions(): DataContainerInterface
105
    {
106
        return $this->options;
107
    }
108
}
109