| Conditions | 5 |
| Paths | 9 |
| Total Lines | 58 |
| 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 |
||
| 25 | function sendDeployNotification($subject) |
||
| 26 | { |
||
| 27 | $url = get('notify_channel_url'); |
||
| 28 | |||
| 29 | if (! $url) { |
||
| 30 | throw new \UnexpectedValueException('[Laravel-Deployer] Not found webhook url!'); |
||
| 31 | } |
||
| 32 | |||
| 33 | $notifyBy = get('notify_by', 'webhook'); |
||
| 34 | |||
| 35 | switch ($notifyBy) { |
||
| 36 | case 'wechat_bot': |
||
| 37 | $content = '在 '.get('environment').' 环境更新 '.get('branch').' 分支 '; |
||
| 38 | $formParams = [ |
||
| 39 | 'msgtype' => 'news', |
||
| 40 | 'news' => [ |
||
| 41 | 'articles' => [ |
||
| 42 | [ |
||
| 43 | 'title' => get('user').' '.$subject, |
||
| 44 | 'description' => $content, |
||
| 45 | 'url' => get('app_repo_url', 'https://github.com'), |
||
| 46 | 'picurl' => get('pic_url', 'https://picsum.photos/id/'.rand(1, 1000).'/800/600'), |
||
| 47 | ], |
||
| 48 | ], |
||
| 49 | ], |
||
| 50 | ]; |
||
| 51 | break; |
||
| 52 | default: |
||
| 53 | $content = implode("\n", [ |
||
| 54 | $subject, |
||
| 55 | '应用名称: '.get('application'), |
||
| 56 | '发布者: '.get('user'), |
||
| 57 | '分支名: '.get('branch'), |
||
| 58 | '环境: '.get('environment'), |
||
| 59 | ]); |
||
| 60 | $formParams = ['text' => $content]; |
||
| 61 | break; |
||
| 62 | } |
||
| 63 | |||
| 64 | if (get('group_notify')) { |
||
| 65 | sendHttpRequest($url, $formParams); |
||
| 66 | } |
||
| 67 | |||
| 68 | $deployedWebookUrl = get('deployed_webhook_url'); |
||
| 69 | |||
| 70 | if ($deployedWebookUrl) { |
||
| 71 | $deployedData = [ |
||
| 72 | 'application' => get('application'), |
||
| 73 | 'user' => get('user'), |
||
| 74 | 'branch' => get('branch'), |
||
| 75 | 'environment' => get('environment'), |
||
| 76 | 'app_repo_url' => get('app_repo_url', 'https://github.com'), |
||
| 77 | ]; |
||
| 78 | sendHttpRequest($deployedWebookUrl, $deployedData); |
||
| 79 | } |
||
| 80 | |||
| 81 | return writeln($content); |
||
| 82 | } |
||
| 83 | |||
| 91 |