literat /
srazvs
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 App\Services; |
||
| 4 | |||
| 5 | use App\Models\SettingsModel; |
||
| 6 | use Nette\Mail\IMailer; |
||
| 7 | use Nette\Mail\Message; |
||
| 8 | use Tracy\Debugger; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Emailer |
||
| 12 | * |
||
| 13 | * Class for hadling and sending e-mails |
||
| 14 | * |
||
| 15 | * @created 2011-09-16 |
||
| 16 | * @author Tomas Litera <[email protected]> |
||
| 17 | */ |
||
| 18 | 1 | class Emailer |
|
| 19 | { |
||
| 20 | /** @var SmtpMailer */ |
||
| 21 | private $mailer; |
||
| 22 | |||
| 23 | /** @var SettingsModel */ |
||
| 24 | private $settings; |
||
| 25 | |||
| 26 | /* Constructor */ |
||
| 27 | public function __construct(SettingsModel $settings, IMailer $mailer) |
||
| 28 | { |
||
| 29 | 1 | $this->mailer = $mailer; |
|
|
0 ignored issues
–
show
|
|||
| 30 | 1 | $this->settings = $settings; |
|
| 31 | 1 | } |
|
| 32 | |||
| 33 | /** |
||
| 34 | * Send an e-mail to recipient |
||
| 35 | * |
||
| 36 | * @param array recipient e-mail and name |
||
| 37 | * @param string subject |
||
| 38 | * @param string message |
||
| 39 | * @param array bcc |
||
| 40 | * @return bool true | false (log the exception) |
||
| 41 | */ |
||
| 42 | public function sendMail($recipients, $subject, $body, array $bccMail = NULL) |
||
| 43 | { |
||
| 44 | 1 | $message = new Message; |
|
| 45 | 1 | $message->setFrom('[email protected]', 'Srazy VS'); |
|
| 46 | |||
| 47 | 1 | foreach($recipients as $recipient) { |
|
| 48 | 1 | $message->addTo( |
|
| 49 | 1 | $recipient->email, |
|
| 50 | 1 | trim($recipient->name . ' ' . $recipient->surname) |
|
| 51 | ); |
||
| 52 | } |
||
| 53 | // add bcc |
||
| 54 | 1 | if(!empty($bccMail)) { |
|
| 55 | 1 | foreach ($bccMail as $bccMail => $bccName) { |
|
|
0 ignored issues
–
show
The expression
$bccMail of type integer|string|array is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
Loading history...
|
|||
| 56 | 1 | $message->addBcc($bccMail, $bccName); |
|
| 57 | } |
||
| 58 | } |
||
| 59 | // create subject |
||
| 60 | 1 | $message->subject = $subject; |
|
| 61 | // create HTML body |
||
| 62 | 1 | $message->htmlBody = $body; |
|
| 63 | // create alternative message without HTML tags |
||
| 64 | 1 | $message->body = strip_tags($body); |
|
| 65 | // sending e-mail or error status |
||
| 66 | try { |
||
| 67 | 1 | $this->mailer->send($message); |
|
| 68 | 1 | return true; |
|
| 69 | } catch(Exception $e) { |
||
|
0 ignored issues
–
show
The class
App\Services\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?
Scrutinizer analyzes your It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis. Loading history...
|
|||
| 70 | Debugger::log($e, 'error'); |
||
| 71 | return false; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Get e-mail template from settings |
||
| 77 | * |
||
| 78 | * @param string type of template |
||
| 79 | * @return array subject and message |
||
| 80 | */ |
||
| 81 | public function getTemplate($type) |
||
| 82 | { |
||
| 83 | 1 | $json = $this->settings->getMailJSON($type); |
|
| 84 | |||
| 85 | 1 | $subject = html_entity_decode($json->subject); |
|
| 86 | 1 | $message = html_entity_decode($json->message); |
|
| 87 | |||
| 88 | return array( |
||
| 89 | 1 | 'subject' => $subject, |
|
| 90 | 1 | 'message' => $message, |
|
| 91 | ); |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Sends an e-mail to lecture master |
||
| 96 | * |
||
| 97 | * @param array recipient mail and name |
||
| 98 | * @param string guid |
||
| 99 | * @param string program | block |
||
| 100 | * @return mixed true | error information |
||
| 101 | */ |
||
| 102 | public function tutor($recipients, $guid, $type) |
||
| 103 | { |
||
| 104 | 1 | $lang['block']['cs'] = "bloku"; |
|
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$lang was never initialized. Although not strictly required by PHP, it is generally a good practice to add $lang = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. Loading history...
|
|||
| 105 | 1 | $lang['program']['cs'] = "programu"; |
|
| 106 | |||
| 107 | 1 | $tutorFormUrl = PRJ_DIR . "annotation/edit/{$type}/{$guid}"; |
|
| 108 | |||
| 109 | // e-mail templates |
||
| 110 | 1 | $template = $this->getTemplate('tutor'); |
|
| 111 | 1 | $subject = $template['subject']; |
|
| 112 | 1 | $message = $template['message']; |
|
| 113 | |||
| 114 | // replacing text variables |
||
| 115 | 1 | $subject = preg_replace('/%%\[typ-anotace\]%%/', $lang[$type]['cs'], $subject); |
|
| 116 | 1 | $message = preg_replace('/%%\[typ-anotace\]%%/', $lang[$type]['cs'], $message); |
|
| 117 | 1 | $message = preg_replace('/%%\[url-formulare\]%%/', $tutorFormUrl, $message); |
|
| 118 | |||
| 119 | // send it |
||
| 120 | 1 | return $this->sendMail($recipients, $subject, $message); |
|
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Sends an after registration summary e-mail to visitor |
||
| 125 | * |
||
| 126 | * @param array recipient mail |
||
| 127 | * @param int check hash code |
||
| 128 | * @param string code for recognition of bank transaction |
||
| 129 | * @return mixed true | error information |
||
| 130 | */ |
||
| 131 | public function sendRegistrationSummary(array $recipientMail, $hash, $code4bank) |
||
| 132 | { |
||
| 133 | // e-mail templates |
||
| 134 | 1 | $template = $this->getTemplate('post_reg'); |
|
| 135 | 1 | $subject = $template['subject']; |
|
| 136 | 1 | $message = $template['message']; |
|
| 137 | |||
| 138 | // replacing text variables |
||
| 139 | 1 | $message = preg_replace('/%%\[kontrolni-hash\]%%/', $hash, $message); |
|
| 140 | 1 | $message = preg_replace('/%%\[variabilni-symbol\]%%/', $code4bank, $message); |
|
| 141 | |||
| 142 | // send it |
||
| 143 | 1 | return $this->sendMail($recipientMail, $subject, $message); |
|
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Get e-mail templates from settings |
||
| 148 | * |
||
| 149 | * @param mixed id numbers in row |
||
| 150 | * @param string type of template |
||
| 151 | * @return array subject and message |
||
| 152 | */ |
||
| 153 | public function sendPaymentInfo($recipients, $type) |
||
| 154 | { |
||
| 155 | // e-mail templates |
||
| 156 | 1 | $template = $this->getTemplate($type); |
|
| 157 | 1 | $subject = $template['subject']; |
|
| 158 | 1 | $message = $template['message']; |
|
| 159 | |||
| 160 | 1 | return $this->sendMail($recipients, $subject, $message); |
|
| 161 | } |
||
| 162 | } |
||
| 163 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..