Conditions | 12 |
Paths | 196 |
Total Lines | 106 |
Code Lines | 63 |
Lines | 0 |
Ratio | 0 % |
Changes | 8 | ||
Bugs | 2 | Features | 3 |
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 | ], true); |
||
126 | |||
127 | if ($isPolitics) { |
||
128 | $message->italic(sprintf( |
||
129 | '@%s, за родину! ' . str_repeat(' :monkey: ', random_int(1, 9)), |
||
130 | $message->user->login |
||
131 | )); |
||
132 | } |
||
133 | |||
134 | |||
135 | } |
||
136 | |||
137 | return $message; |
||
138 | } |
||
139 | } |
||
140 |