| Conditions | 13 |
| Paths | 388 |
| Total Lines | 111 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 10 | ||
| Bugs | 2 | Features | 4 |
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 |
||
| 33 | public function handle(Message $message) |
||
| 34 | { |
||
| 35 | if ($message->user->login === \Auth::user()->login) { |
||
| 36 | return $message; |
||
| 37 | } |
||
| 38 | |||
| 39 | $noMentions = !count($message->mentions); |
||
| 40 | |||
| 41 | // Personal message |
||
| 42 | $isBotMention = $message->hasMention(function(User $user) { |
||
| 43 | return $user->login === \Auth::user()->login; |
||
| 44 | }); |
||
| 45 | |||
| 46 | if ($isBotMention || $noMentions) { |
||
| 47 | // Hello all |
||
| 48 | $isHello = Str::contains($message->text_without_special_chars, \Lang::get('personal.hello_query')); |
||
| 49 | |||
| 50 | if ($isHello) { |
||
| 51 | $id = array_rand(\Lang::get('personal.hello')); |
||
| 52 | |||
| 53 | $message->italic(\Lang::get('personal.hello.' . $id, [ |
||
| 54 | 'user' => $message->user->login |
||
| 55 | ])); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | if (!count($message->mentions)) { |
||
| 60 | // Question |
||
| 61 | $isQuestion = Str::contains($message->text_without_special_chars, [ |
||
| 62 | 'можно задать вопрос', |
||
| 63 | 'хочу задать вопрос', |
||
| 64 | 'есть кто', |
||
| 65 | 'кто может помочь', |
||
| 66 | 'помогите пожалуйста' |
||
| 67 | ]); |
||
| 68 | |||
| 69 | if ($isQuestion) { |
||
| 70 | $message->italic(sprintf('@%s, и какой ответ ты ожидаешь услышать?', $message->user->login)); |
||
| 71 | } |
||
| 72 | |||
| 73 | // Question |
||
| 74 | $isCats = Str::contains($message->text_without_special_chars, ['котаны']); |
||
| 75 | |||
| 76 | if ($isCats) { |
||
| 77 | $message->italic(sprintf('@%s, в Пензу езжай со своими котанами \-_\-', $message->user->login)); |
||
| 78 | } |
||
| 79 | |||
| 80 | // Question |
||
| 81 | $isPolitics = Str::contains($message->text_without_special_chars, [ |
||
| 82 | 'яровая', |
||
| 83 | 'пакет яровой', |
||
| 84 | 'пакетом яровой', |
||
| 85 | 'пакете яровой', |
||
| 86 | 'пакету яровой', |
||
| 87 | 'мизулина' |
||
| 88 | ]); |
||
| 89 | |||
| 90 | if ($isPolitics) { |
||
| 91 | $message->italic(sprintf('@%s, :see_no_evil: :fire: ', $message->user->login)); |
||
| 92 | } |
||
| 93 | |||
| 94 | $isRules = in_array($message->text_without_special_chars, [ |
||
| 95 | 'правила чата', |
||
| 96 | 'правила', |
||
| 97 | 'как себя вести', |
||
| 98 | '9 кругов' |
||
| 99 | ], true); |
||
| 100 | |||
| 101 | if ($isRules) { |
||
| 102 | $message->italic(sprintf('@%s, [In rules we trust](http://laravel.su/articles/nine-circles-of-chat)', $message->user->login)); |
||
| 103 | } |
||
| 104 | |||
| 105 | $isBan = in_array($message->text_without_special_chars, [ |
||
| 106 | 'банхаммер', |
||
| 107 | 'хаммер', |
||
| 108 | 'бан', |
||
| 109 | ], true); |
||
| 110 | |||
| 111 | if ($isBan) { |
||
| 112 | $message->italic(sprintf( |
||
| 113 | '@%s, тебе выданы ' . str_repeat(' :hammer: ', random_int(1, 9)) . ' на 0.' . random_int(1, 9) . ' секунды. Наслаждайся ;)', |
||
| 114 | $message->user->login |
||
| 115 | )); |
||
| 116 | } |
||
| 117 | |||
| 118 | $isPolitics = in_array($message->text_without_special_chars, [ |
||
| 119 | 'майдан', |
||
| 120 | 'революция', |
||
| 121 | 'битрикс', |
||
| 122 | 'yii', |
||
| 123 | 'wordpress', |
||
| 124 | 'вордпресс', |
||
| 125 | 'laravel', |
||
| 126 | 'ларавель', |
||
| 127 | 'йии', |
||
| 128 | ], true); |
||
| 129 | |||
| 130 | if ($isPolitics) { |
||
| 131 | $message->italic(sprintf( |
||
| 132 | '@%s, за ' . $message->text_without_special_chars . '! ' . str_repeat(' :monkey: ', random_int(1, 9)), |
||
| 133 | $message->user->login |
||
| 134 | )); |
||
| 135 | } |
||
| 136 | |||
| 137 | if (preg_match('/[a-zA-Z][0-9]/isu', $message->text_without_special_chars)) { |
||
| 138 | $message->italic(sprintf('@%s, %s', $message->user->login, ['мимо', 'ранил', 'убил'][random_int(0, 2)])); |
||
| 139 | } |
||
| 140 | } |
||
| 141 | |||
| 142 | return $message; |
||
| 143 | } |
||
| 144 | } |
||
| 145 |