Conditions | 3 |
Paths | 4 |
Total Lines | 71 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
51 | protected function generateConfigProtected(): void |
||
52 | { |
||
53 | // Уважаемый ${VM_NAME}:\n\n\tВам пришло новое голосовое сообщение длиной ${VM_DUR} |
||
54 | // под номером (number ${VM_MSGNUM})\nв ящик ${VM_MAILBOX} от ${VM_CALLERID}, в ${VM_DATE}. \n\t |
||
55 | $emailsubject = $this->generalSettings['MailTplVoicemailSubject']; |
||
56 | $emailsubject = str_replace(["\n", "\t"], '', $emailsubject); |
||
57 | |||
58 | $emailbody = $this->generalSettings['MailTplVoicemailBody']; |
||
59 | $emailbody = str_replace(["\n", "\t"], ['\n', ''], $emailbody); |
||
60 | |||
61 | $emailfooter = $this->generalSettings['MailTplVoicemailFooter']; |
||
62 | $emailfooter = str_replace(["\n", "\t"], ['\n', ''], $emailfooter); |
||
63 | |||
64 | $from = $this->generalSettings['MailSMTPSenderAddress']; |
||
65 | if (empty($from)) { |
||
66 | $from = $this->generalSettings['MailSMTPUsername']; |
||
67 | } |
||
68 | |||
69 | $timezone = $this->generalSettings['PBXTimezone']; |
||
70 | $msmtpPath = Util::which('voicemail-sender'); |
||
71 | |||
72 | $conf = "[general]\n" . |
||
73 | "format=wav\n" . |
||
74 | "attach=yes\n" . |
||
75 | "maxmsg=100\n" . |
||
76 | "maxsecs=120\n" . |
||
77 | "maxgreet=60\n" . |
||
78 | "maxsilence=10\n" . |
||
79 | "silencethreshold=128\n" . |
||
80 | "maxlogins=3\n" . |
||
81 | "moveheard=yes\n" . |
||
82 | "charset=UTF-8\n" . |
||
83 | "pbxskip=yes\n" . |
||
84 | "fromstring=VoiceMail\n" . |
||
85 | "emailsubject={$emailsubject}\n" . |
||
86 | "emailbody={$emailbody}".'\n\n'."{$emailfooter}\n" . |
||
87 | "emaildateformat=%A, %d %B %Y в %H:%M:%S\n" . |
||
88 | "pagerdateformat=%T %D\n" . |
||
89 | // "mailcmd={$msmtpPath} --file=/etc/msmtp.conf -t\n" . |
||
90 | "mailcmd={$msmtpPath}\n" . |
||
91 | "serveremail={$from}\n\n" . |
||
92 | "[zonemessages]\n" . |
||
93 | "local={$timezone}|'vm-received' q 'digits/at' H 'hours' M 'minutes'\n\n"; |
||
94 | |||
95 | $conf .= "[voicemailcontext]\n"; |
||
96 | |||
97 | $mail_box = $this->generalSettings['VoicemailNotificationsEmail']; |
||
98 | if (empty($mail_box)) { |
||
99 | $mail_box = $this->generalSettings['SystemNotificationsEmail']; |
||
100 | } |
||
101 | $conf .= "admin => admin," . Util::translate("user") . ",{$mail_box},,attach=yes|tz=local|delete=yes\n"; |
||
102 | /* |
||
103 | $peers = Sip::find('type="peer"'); |
||
104 | foreach ($peers as $peer){ |
||
105 | $username = $peer->extension; |
||
106 | $mail_box = ''; |
||
107 | $exten = Extensions::findFirst("number='{$username}'"); |
||
108 | if($exten !== null){ |
||
109 | $user = Users::findFirst("id='{$exten->userid}'"); |
||
110 | if($user !== null){ |
||
111 | $username = $user->username; |
||
112 | $mail_box = $user->email; |
||
113 | } |
||
114 | } |
||
115 | |||
116 | // $conf.= "{$peer->extension} => {$peer->extension},{$username},{$mail_box},,attach=yes|tz=local|delete=yes\n"; |
||
117 | $conf.= "{$peer->extension} => {$peer->extension},{$username},{$mail_box},,attach=yes|tz=local\n"; |
||
118 | } |
||
119 | //*/ |
||
120 | |||
121 | Util::fileWriteContent($this->config->path('asterisk.astetcdir') . '/voicemail.conf', $conf); |
||
122 | } |
||
152 | } |