|
1
|
|
|
<?php |
|
2
|
|
|
namespace FMUP\ErrorHandler\Plugin; |
|
3
|
|
|
|
|
4
|
|
|
use FMUP\Sapi; |
|
5
|
|
|
|
|
6
|
|
|
class Mail extends Abstraction |
|
7
|
|
|
{ |
|
8
|
1 |
|
public function canHandle() |
|
9
|
|
|
{ |
|
10
|
1 |
|
$config = $this->getBootstrap()->getConfig(); |
|
11
|
|
|
return ( |
|
12
|
1 |
|
(!$this->getException() instanceof \FMUP\Exception\Status) |
|
13
|
1 |
|
&& !$config->get('use_daily_alert') && !$this->iniGet('display_errors') |
|
14
|
|
|
); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param string $key |
|
19
|
|
|
* @return string |
|
20
|
|
|
* @codeCoverageIgnore |
|
21
|
|
|
*/ |
|
22
|
|
|
protected function iniGet($key) |
|
23
|
|
|
{ |
|
24
|
|
|
return ini_get($key); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @return $this |
|
29
|
|
|
*/ |
|
30
|
1 |
|
public function handle() |
|
31
|
|
|
{ |
|
32
|
1 |
|
$this->sendMail($this->getBody()); |
|
33
|
1 |
|
return $this; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $body |
|
38
|
|
|
* @return bool |
|
39
|
|
|
* @throws \Exception |
|
40
|
|
|
* @throws \FMUP\Config\Exception |
|
41
|
|
|
* @throws \FMUP\Exception |
|
42
|
|
|
* @throws \phpmailerException |
|
43
|
|
|
*/ |
|
44
|
1 |
|
protected function sendMail($body) |
|
45
|
|
|
{ |
|
46
|
1 |
|
$config = $this->getBootstrap()->getConfig(); |
|
47
|
|
|
/** @var \FMUP\Request\Http $request */ |
|
48
|
1 |
|
$request = $this->getRequest(); |
|
49
|
1 |
|
$serverName = $this->getBootstrap()->getSapi()->get() != Sapi::CLI |
|
50
|
1 |
|
? $request->getServer(\FMUP\Request\Http::SERVER_NAME) |
|
51
|
1 |
|
: $config->get('erreur_mail_sujet'); |
|
52
|
1 |
|
$mail = $this->createMail($config); |
|
53
|
1 |
|
$mail->From = $config->get('mail_robot'); |
|
|
|
|
|
|
54
|
1 |
|
$mail->FromName = $config->get('mail_robot_name'); |
|
|
|
|
|
|
55
|
1 |
|
$mail->Subject = '[Erreur] ' . $serverName; |
|
56
|
1 |
|
$mail->AltBody = (string)$body; |
|
57
|
1 |
|
$mail->WordWrap = 50; // set word wrap |
|
58
|
|
|
|
|
59
|
1 |
|
$mail->Body = (string)$body; |
|
60
|
|
|
|
|
61
|
1 |
|
$recipients = $config->get('mail_support'); |
|
62
|
1 |
|
if (strpos($recipients, ',') === false) { |
|
63
|
1 |
|
$mail->AddAddress($recipients, "Support"); |
|
|
|
|
|
|
64
|
|
|
} else { |
|
65
|
1 |
|
$tab_recipients = explode(',', $recipients); |
|
66
|
1 |
|
foreach ($tab_recipients as $recipient) { |
|
67
|
1 |
|
$mail->AddAddress($recipient); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
1 |
|
return $mail->Send(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Creates a new mail for config |
|
75
|
|
|
* @param \FMUP\Config\ConfigInterface $config |
|
76
|
|
|
* @return \FMUP\Mail |
|
77
|
|
|
* @codeCoverageIgnore |
|
78
|
|
|
*/ |
|
79
|
|
|
protected function createMail(\FMUP\Config\ConfigInterface $config) |
|
80
|
|
|
{ |
|
81
|
|
|
return new \FMUP\Mail($config); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @todo clean this |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
1 |
|
protected function getBody() |
|
89
|
|
|
{ |
|
90
|
1 |
|
$view = new \FMUP\View(array('exception' => $this->getException())); |
|
91
|
1 |
|
return $view->setViewPath($this->getViewPath())->render(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
1 |
|
protected function getViewPath() |
|
95
|
|
|
{ |
|
96
|
1 |
|
return __DIR__ . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array('Mail', 'render.phtml')); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.