| Conditions | 12 |
| Paths | 24 |
| Total Lines | 46 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 67 | private function show($msg): bool |
||
| 68 | { |
||
| 69 | if (empty($msg)) { |
||
| 70 | return true; |
||
| 71 | } |
||
| 72 | $nt = config('dtapp.exception.type', ''); |
||
| 73 | if (!empty($nt) && $nt === 'dingtalk') { |
||
| 74 | $access_token = config('dtapp.exception.dingtalk.access_token', ''); |
||
| 75 | if (!empty($access_token)) { |
||
| 76 | return DingTalkService::instance() |
||
| 77 | ->accessToken($access_token) |
||
|
|
|||
| 78 | ->text($msg); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | if (!empty($nt) && $nt === 'qyweixin') { |
||
| 82 | $key = config('dtapp.exception.qyweixin.key', ''); |
||
| 83 | if (!empty($key)) { |
||
| 84 | return QyService::instance() |
||
| 85 | ->key($key) |
||
| 86 | ->text($msg); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | if (!empty($nt) && $nt === 'wechat') { |
||
| 90 | $openid = config('dtapp.exception.wechat.openid', ''); |
||
| 91 | $ip = config('dtapp.exception.wechat.ip', '未配置'); |
||
| 92 | $seip = get_ip(); |
||
| 93 | $ipinfo = QqWryService::instance()->getLocation($seip); |
||
| 94 | if (!isset($ipinfo['location_all'])) { |
||
| 95 | $ipinfo['location_all'] = ''; |
||
| 96 | } |
||
| 97 | if (!empty($openid)) { |
||
| 98 | return HttpService::instance() |
||
| 99 | ->url("https://api.dtapp.net/v1/wechatmp/tmplmsgWebError/openid/{$openid}") |
||
| 100 | ->post() |
||
| 101 | ->data([ |
||
| 102 | 'domain' => request()->domain(), |
||
| 103 | 'url' => request()->url(), |
||
| 104 | 'node' => config('dtapp.exception.wechat.node', ''), |
||
| 105 | 'info' => "ServerIp:" . $ip . ";CdnIp:" . $_SERVER['REMOTE_ADDR'] . ";ClientIp:" . get_ip(), |
||
| 106 | 'ip' => $ipinfo['location_all'], |
||
| 107 | 'error' => base64_encode($msg) |
||
| 108 | ]) |
||
| 109 | ->toArray(); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | return true; |
||
| 113 | } |
||
| 115 |