| Conditions | 3 |
| Paths | 4 |
| Total Lines | 51 |
| Code Lines | 36 |
| 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 |
||
| 29 | public static function startLog($timeout = 300): PBXApiResult |
||
| 30 | { |
||
| 31 | $res = new PBXApiResult(); |
||
| 32 | $res->processor = __METHOD__; |
||
| 33 | self::stopLog(); |
||
| 34 | $dir_all_log = System::getLogDir(); |
||
| 35 | $findPath = Util::which('find'); |
||
| 36 | Util::mwExec("{$findPath} {$dir_all_log}" . '/ -name *_start_all_log* | xargs rm -rf'); |
||
| 37 | // Получим каталог с логами. |
||
| 38 | $dirlog = $dir_all_log . '/dir_start_all_log'; |
||
| 39 | Util::mwMkdir($dirlog); |
||
| 40 | |||
| 41 | $pingPath = Util::which('ping'); |
||
| 42 | Util::mwExecBg("{$pingPath} 8.8.8.8 -w 2", "{$dirlog}/ping_8888.log"); |
||
| 43 | Util::mwExecBg("{$pingPath} ya.ru -w 2", "{$dirlog}/ping_8888.log"); |
||
| 44 | |||
| 45 | $opensslPath = Util::which('openssl'); |
||
| 46 | Util::mwExecBgWithTimeout( |
||
| 47 | "{$opensslPath} s_client -connect lm.miko.ru:443 > {$dirlog}/openssl_lm_miko_ru.log", |
||
| 48 | 1 |
||
| 49 | ); |
||
| 50 | Util::mwExecBgWithTimeout( |
||
| 51 | "{$opensslPath} s_client -connect lic.miko.ru:443 > {$dirlog}/openssl_lic_miko_ru.log", |
||
| 52 | 1 |
||
| 53 | ); |
||
| 54 | $routePath = Util::which('route'); |
||
| 55 | Util::mwExecBg("{$routePath} -n ", " {$dirlog}/rout_n.log"); |
||
| 56 | |||
| 57 | $asteriskPath = Util::which('asterisk'); |
||
| 58 | Util::mwExecBg("{$asteriskPath} -rx 'pjsip show registrations' ", " {$dirlog}/pjsip_show_registrations.log"); |
||
| 59 | Util::mwExecBg("{$asteriskPath} -rx 'pjsip show endpoints' ", " {$dirlog}/pjsip_show_endpoints.log"); |
||
| 60 | Util::mwExecBg("{$asteriskPath} -rx 'pjsip show contacts' ", " {$dirlog}/pjsip_show_contacts.log"); |
||
| 61 | |||
| 62 | $php_log = '/var/log/php_error.log'; |
||
| 63 | if (file_exists($php_log)) { |
||
| 64 | $cpPath = Util::which('cp'); |
||
| 65 | Util::mwExec("{$cpPath} {$php_log} {$dirlog}"); |
||
| 66 | } |
||
| 67 | |||
| 68 | $network = new Network(); |
||
| 69 | $arr_eth = $network->getInterfacesNames(); |
||
| 70 | $tcpdumpPath = Util::which('tcpdump'); |
||
| 71 | foreach ($arr_eth as $eth) { |
||
| 72 | Util::mwExecBgWithTimeout( |
||
| 73 | "{$tcpdumpPath} -i {$eth} -n -s 0 -vvv -w {$dirlog}/{$eth}.pcap", |
||
| 74 | $timeout, |
||
| 75 | "{$dirlog}/{$eth}_out.log" |
||
| 76 | ); |
||
| 77 | } |
||
| 78 | $res->success=true; |
||
| 79 | return $res; |
||
| 80 | } |
||
| 215 | } |