Issues (9)

src/Email/Participants.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FH\Bundle\MailerBundle\Email;
6
7
use FH\Bundle\MailerBundle\Exception\InvalidArgumentException;
0 ignored issues
show
The type FH\Bundle\MailerBundle\E...nvalidArgumentException 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...
8
use Symfony\Component\Mime\Address;
9
10
final class Participants
11
{
12
    /** @var Address|null */
13
    private $sender;
14
15
    /** @var array */
16
    private $from;
17
18
    /** @var array */
19
    private $replyTo;
20
21
    /** @var array */
22
    private $to;
23
24
    /** @var array */
25
    private $cc;
26
27
    /** @var array */
28
    private $bcc;
29
30 1
    public static function fromArray(array $participants): self
31
    {
32 1
        $createAddress = static function (array $address) {
33 1
            return self::createAddress($address);
34 1
        };
35
36 1
        return new self(
37 1
            isset($participants['sender']) && \is_array($participants['sender']) ? self::createAddress($participants['sender']) : null,
38 1
            array_map($createAddress, $participants['from'] ?? []),
39 1
            array_map($createAddress, $participants['reply_to'] ?? []),
40 1
            array_map($createAddress, $participants['to'] ?? []),
41 1
            array_map($createAddress, $participants['cc'] ?? []),
42 1
            array_map($createAddress, $participants['bcc'] ?? [])
43
        );
44
    }
45
46 1
    public function __construct(
47
        Address $sender = null,
48
        array $from = [],
49
        array $replyTo = [],
50
        array $to = [],
51
        array $cc = [],
52
        array $bcc = []
53
    ) {
54 1
        $this->sender = $sender;
55 1
        $this->from = $from;
56 1
        $this->replyTo = $replyTo;
57 1
        $this->to = $to;
58 1
        $this->cc = $cc;
59 1
        $this->bcc = $bcc;
60 1
    }
61
62 1
    public function getSender(): ?Address
63
    {
64 1
        return $this->sender;
65
    }
66
67 1
    public function hasSender(): bool
68
    {
69 1
        return $this->sender instanceof Address;
70
    }
71
72
    /**
73
     * @return Address[]
74
     */
75 1
    public function getFrom(): array
76
    {
77 1
        return $this->from;
78
    }
79
80 1
    public function hasFrom(): bool
81
    {
82 1
        return !empty($this->from);
83
    }
84
85
    /**
86
     * @return Address[]
87
     */
88 1
    public function getReplyTo(): array
89
    {
90 1
        return $this->replyTo;
91
    }
92
93 1
    public function hasReplyTo(): bool
94
    {
95 1
        return !empty($this->replyTo);
96
    }
97
98
    /**
99
     * @return Address[]
100
     */
101 1
    public function getTo(): array
102
    {
103 1
        return $this->to;
104
    }
105
106 1
    public function hasTo(): bool
107
    {
108 1
        return !empty($this->to);
109
    }
110
111
    /**
112
     * @return Address[]
113
     */
114 1
    public function getCc(): array
115
    {
116 1
        return $this->cc;
117
    }
118
119 1
    public function hasCc(): bool
120
    {
121 1
        return !empty($this->cc);
122
    }
123
124
    /**
125
     * @return Address[]
126
     */
127 1
    public function getBcc(): array
128
    {
129 1
        return $this->bcc;
130
    }
131
132 1
    public function hasBcc(): bool
133
    {
134 1
        return !empty($this->bcc);
135
    }
136
137 1
    private static function createAddress(array $address): Address
138
    {
139 1
        return new Address($address['address'], $address['name'] ?? '');
140
    }
141
}
142