Completed
Push — master ( efdf87...799afb )
by Kirill
03:17
created

MarkdownAdviserMiddleware::handle()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 28
Code Lines 16

Duplication

Lines 5
Ratio 17.86 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 5
loc 28
rs 8.439
cc 5
eloc 16
nc 7
nop 1
1
<?php
2
namespace App\Middlewares;
3
4
use App\Message;
5
use App\Gitter\Middleware\MiddlewareInterface;
6
7
/**
8
 * Class MarkdownAdviserMiddleware
9
 * @package App\Gitter\Middleware
10
 */
11
class MarkdownAdviserMiddleware implements MiddlewareInterface
12
{
13
    /**
14
     * @param Message $message
15
     * @return mixed
16
     */
17
    public function handle(Message $message)
18
    {
19
        $text = $message->escaped_text;
20
21
        if (preg_match('/^(@.*?\s)?(?:оформи\sкод|код\sоформи).*?$/isu', $text)) {
22
23
            $hasMentions = count($message->mentions);
24
            $mention = null;
25
26 View Code Duplication
            if ($hasMentions) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
                $mention = $message->mentions[0]->login === \Auth::user()->login
28
                    ? $message->user
29
                    : $message->mentions[0];
30
            }
31
32
            $answer = $mention
33
                ? \Lang::get('markdown.personal', [
34
                    'user'  => $mention->login,
35
                ])
36
                : \Lang::get('markdown.common');
37
38
            $message->italic($answer);
39
40
            return null;
41
        }
42
43
        return $message;
44
    }
45
}
46