| Conditions | 7 | 
| Paths | 5 | 
| Total Lines | 52 | 
| Code Lines | 29 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 2 | ||
| Bugs | 0 | Features | 1 | 
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  | 
            ||
| 18 | public function handle(Message $message)  | 
            ||
| 19 |     { | 
            ||
| 20 |         if (preg_match('/^(@.*?\s)?(информация|доки|документация|larvel doc)\s+(?:про|по)?\s*(.*?)$/isu', $message->text, $matches)) { | 
            ||
| 21 |             if (!trim($matches[3])) { | 
            ||
| 22 | return $message;  | 
            ||
| 23 | }  | 
            ||
| 24 | |||
| 25 | $client = new Client(  | 
            ||
| 26 | '8BB87I11DE',  | 
            ||
| 27 | '8e1d446d61fce359f69cd7c8b86a50de'  | 
            ||
| 28 | );  | 
            ||
| 29 | |||
| 30 |             $result = $client->initIndex('docs')->search($matches[3]); | 
            ||
| 31 | |||
| 32 |             if (! isset($result['hits'])) { | 
            ||
| 33 |                 $message->italic('По вашему запросу ничего не найдено'); | 
            ||
| 34 | return null;  | 
            ||
| 35 | }  | 
            ||
| 36 | |||
| 37 | $response = '';  | 
            ||
| 38 | |||
| 39 | $hits = new Collection($result['hits']);  | 
            ||
| 40 | |||
| 41 |             $hits->unique(function($row) { | 
            ||
| 42 | return $row['h1'];  | 
            ||
| 43 |             })->map(function($row) { | 
            ||
| 44 | $row['link'] = 'https://laravel.com/docs/5.2/'.$row['link'];  | 
            ||
| 45 | return $row;  | 
            ||
| 46 |             })->take(3)->each(function($row) use(&$response) { | 
            ||
| 47 | $title = '';  | 
            ||
| 48 |                 foreach (['h1', 'h2', 'h3', 'h4', 'h5'] as $tag) { | 
            ||
| 49 |                     if (isset($row[$tag])) { | 
            ||
| 50 | $title .= ' : '.$row[$tag];  | 
            ||
| 51 | }  | 
            ||
| 52 | }  | 
            ||
| 53 | |||
| 54 |                 $response .= "[*] [i][url={$row['link']}]{$title}[/url][/i]".PHP_EOL; | 
            ||
| 55 | });  | 
            ||
| 56 | |||
| 57 |             if (! empty($response)) { | 
            ||
| 58 |                 $message->answer(trans('search.results', [ | 
            ||
| 59 | 'results' => '[i]Вот что нашел в документации:[/i] [list]'.PHP_EOL.$response.PHP_EOL.'[/list]'  | 
            ||
| 60 | ]));  | 
            ||
| 61 | }  | 
            ||
| 62 | |||
| 63 | |||
| 64 | |||
| 65 | return null;  | 
            ||
| 66 | }  | 
            ||
| 67 | |||
| 68 | return $message;  | 
            ||
| 69 | }  | 
            ||
| 70 | |||
| 79 |