This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace SfCod\EmailEngineBundle\Mailer; |
||
4 | |||
5 | use Psr\Log\LoggerInterface; |
||
6 | use SfCod\EmailEngineBundle\Exception\RepositoryUnavailableException; |
||
7 | use SfCod\EmailEngineBundle\Repository\RepositoryInterface; |
||
8 | use SfCod\EmailEngineBundle\Sender\MessageOptionsInterface; |
||
9 | use SfCod\EmailEngineBundle\Sender\SenderInterface; |
||
10 | use SfCod\EmailEngineBundle\Template\ParametersAwareInterface; |
||
11 | use SfCod\EmailEngineBundle\Template\Params\ParameterResolverInterface; |
||
12 | use SfCod\EmailEngineBundle\Template\RepositoryAwareInterface; |
||
13 | use SfCod\EmailEngineBundle\Template\TemplateInterface; |
||
14 | |||
15 | /** |
||
16 | * Class Mailer |
||
17 | * |
||
18 | * @author Virchenko Maksim <[email protected]> |
||
19 | * |
||
20 | * @package SfCod\EmailEngineBundle\Sender |
||
21 | */ |
||
22 | class Mailer |
||
23 | { |
||
24 | /** |
||
25 | * Configuration with ordered senders |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | private $configuration = []; |
||
30 | |||
31 | /** |
||
32 | * Senders for email sending |
||
33 | * |
||
34 | * @var SenderInterface[] |
||
35 | */ |
||
36 | private $senders = []; |
||
37 | |||
38 | /** |
||
39 | * Repositories list for senders |
||
40 | * |
||
41 | * @var RepositoryInterface[] |
||
42 | */ |
||
43 | private $repositories = []; |
||
44 | |||
45 | /** |
||
46 | * @var ParameterResolverInterface |
||
47 | */ |
||
48 | private $parameterResolver; |
||
49 | |||
50 | /** |
||
51 | * @var LoggerInterface |
||
52 | */ |
||
53 | private $logger; |
||
54 | |||
55 | /** |
||
56 | * EmailSender constructor. |
||
57 | * |
||
58 | * @param ParameterResolverInterface $parameterResolver |
||
59 | * @param LoggerInterface $logger |
||
60 | */ |
||
61 | public function __construct(ParameterResolverInterface $parameterResolver, LoggerInterface $logger) |
||
62 | { |
||
63 | $this->parameterResolver = $parameterResolver; |
||
64 | $this->logger = $logger; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Set senders |
||
69 | * |
||
70 | * @param array $senders |
||
71 | */ |
||
72 | public function setSenders(array $senders) |
||
73 | { |
||
74 | $this->senders = $senders; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param RepositoryInterface[] $repositories |
||
79 | */ |
||
80 | public function setRepositories(array $repositories) |
||
81 | { |
||
82 | $this->repositories = $repositories; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @param array $configuration |
||
87 | */ |
||
88 | public function setConfiguration(array $configuration) |
||
89 | { |
||
90 | $this->configuration = $configuration; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Send email template |
||
95 | * |
||
96 | * @param TemplateInterface $template |
||
97 | * @param array|string $emails |
||
98 | * @param null|MessageOptionsInterface $options |
||
99 | * |
||
100 | * @return int |
||
101 | */ |
||
102 | public function send(TemplateInterface $template, $emails, ?MessageOptionsInterface $options = null): int |
||
103 | { |
||
104 | $sentCount = 0; |
||
105 | |||
106 | foreach ($this->configuration as $config) { |
||
107 | try { |
||
108 | $concreteTemplate = clone $template; |
||
109 | $sender = array_merge($config['sender'], ['options' => $options]); |
||
110 | $concreteSender = $this->makeSender($sender['class'], $sender['options']); |
||
0 ignored issues
–
show
|
|||
111 | |||
112 | if ($concreteTemplate instanceof RepositoryAwareInterface) { |
||
113 | $concreteTemplate->setRepository($this->makeRepository($config['repository']['class'], $concreteTemplate, $config['repository']['arguments'])); |
||
114 | } |
||
115 | |||
116 | if ($concreteTemplate instanceof ParametersAwareInterface) { |
||
117 | $concreteTemplate->setParameterResolver($this->parameterResolver); |
||
118 | } |
||
119 | |||
120 | if ($concreteSender->send($concreteTemplate, $emails)) { |
||
121 | ++$sentCount; |
||
122 | |||
123 | break; |
||
124 | } |
||
125 | } catch (RepositoryUnavailableException $e) { |
||
126 | $this->logger->error($e->getMessage(), ['exception' => $e]); |
||
127 | |||
128 | // Try next sender |
||
129 | } |
||
130 | } |
||
131 | |||
132 | return $sentCount; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Make email engine sender |
||
137 | * |
||
138 | * @param string $senderName |
||
139 | * @param MessageOptionsInterface|null $options |
||
140 | * |
||
141 | * @return SenderInterface |
||
142 | */ |
||
143 | protected function makeSender(string $senderName, ?MessageOptionsInterface $options = null): SenderInterface |
||
144 | { |
||
145 | /** @var SenderInterface $sender */ |
||
146 | $sender = $this->senders[$senderName]; |
||
147 | |||
148 | if ($options) { |
||
149 | $sender->setOptions($options); |
||
150 | } |
||
151 | |||
152 | return $sender; |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * Make email engine repository |
||
157 | * |
||
158 | * @param string $repositoryName |
||
159 | * @param TemplateInterface $template |
||
160 | * @param array $arguments |
||
161 | * |
||
162 | * @return RepositoryInterface |
||
163 | */ |
||
164 | protected function makeRepository(string $repositoryName, TemplateInterface $template, array $arguments = []): RepositoryInterface |
||
165 | { |
||
166 | /** @var RepositoryInterface $repository */ |
||
167 | $repository = $this->repositories[$repositoryName]; |
||
168 | $repository->connect($template, $arguments); |
||
169 | |||
170 | return $repository; |
||
171 | } |
||
172 | } |
||
173 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: