| Conditions | 9 |
| Paths | 48 |
| Total Lines | 58 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 39 | public function processUpdate():void |
||
| 40 | { |
||
| 41 | $sqlite3Path = Util::which('sqlite3'); |
||
| 42 | |||
| 43 | /** @var \MikoPBX\Common\Models\FirewallRules $rule */ |
||
| 44 | $result = FirewallRules::find(); |
||
| 45 | foreach ($result as $rule) { |
||
| 46 | /** @var \MikoPBX\Common\Models\NetworkFilters $network_filter */ |
||
| 47 | $network_filter = NetworkFilters::findFirst($rule->networkfilterid); |
||
| 48 | if ($network_filter === null) { |
||
| 49 | // Это "битая" роль, необходимо ее удалить. Нет ссылки на подсеть. |
||
| 50 | $rule->delete(); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | // Корректировка AstDB |
||
| 55 | $astdb_file = $this->config->path('astDatabase.dbfile'); |
||
| 56 | if (file_exists($astdb_file)) { |
||
| 57 | // С переходом на PJSIP удалим статусы SIP. |
||
| 58 | Util::mwExec("{$sqlite3Path} {$astdb_file} 'DELETE FROM astdb WHERE key LIKE \"/UserBuddyStatus/SIP%\"'"); |
||
| 59 | } |
||
| 60 | |||
| 61 | PBX::checkCodec('ilbc', 'iLBC', 'audio'); |
||
| 62 | PBX::checkCodec('opus', 'Opus Codec', 'audio'); |
||
| 63 | |||
| 64 | $PrivateKey = $this->mikoPBXConfig->getGeneralSettings('WEBHTTPSPrivateKey'); |
||
| 65 | $PublicKey = $this->mikoPBXConfig->getGeneralSettings('WEBHTTPSPublicKey'); |
||
| 66 | if (empty($PrivateKey) || empty($PublicKey)) { |
||
| 67 | $certs = Util::generateSslCert(); |
||
| 68 | $this->mikoPBXConfig->setGeneralSettings('WEBHTTPSPrivateKey', $certs['PrivateKey']); |
||
| 69 | $this->mikoPBXConfig->setGeneralSettings('WEBHTTPSPublicKey', $certs['PublicKey']); |
||
| 70 | } |
||
| 71 | |||
| 72 | |||
| 73 | $app_number = '10003246'; |
||
| 74 | $d_app = DialplanApplications::findFirst('extension="' . $app_number . '"'); |
||
| 75 | if ($d_app === null) { |
||
| 76 | $app_text = '1,Answer()' . "\n" . |
||
| 77 | 'n,AGI(cdr_connector.php,${ISTRANSFER}dial_answer)' . "\n" . |
||
| 78 | 'n,Echo()' . "\n" . |
||
| 79 | 'n,Hangup()' . "\n"; |
||
| 80 | $d_app = new DialplanApplications(); |
||
| 81 | $d_app->applicationlogic = base64_encode($app_text); |
||
| 82 | $d_app->extension = $app_number; |
||
| 83 | $d_app->description = 'Echos audio and video back to the caller as soon as it is received. Used to test connection delay.'; |
||
| 84 | $d_app->name = 'Echo test'; |
||
| 85 | $d_app->type = 'plaintext'; |
||
| 86 | $d_app->uniqid = 'DIALPLAN-APPLICATION-' . md5(time()); |
||
| 87 | |||
| 88 | if ($d_app->save()) { |
||
| 89 | $extension = Extensions::findFirst("number = '{$app_number}'"); |
||
| 90 | if ($extension === null) { |
||
| 91 | $extension = new Extensions(); |
||
| 92 | $extension->number = $app_number; |
||
| 93 | $extension->type = Extensions::TYPE_DIALPLAN_APPLICATION; |
||
| 94 | $extension->callerid = $d_app->name; |
||
| 95 | $extension->show_in_phonebook = '1'; |
||
| 96 | $extension->save(); |
||
| 97 | } |
||
| 101 | } |