Completed
Push — master ( a1f3ed...74c577 )
by Kirill
02:49
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 0
Metric Value
c 1
b 0
f 0
dl 5
loc 28
rs 8.439
cc 5
eloc 16
nc 7
nop 1
1
<?php
2
namespace Domains\Bot\Middlewares;
3
4
use Domains\Message;
5
use Interfaces\Gitter\Middleware\MiddlewareInterface;
6
7
/**
8
 * Class MarkdownAdviserMiddleware
9
 */
10
class MarkdownAdviserMiddleware implements MiddlewareInterface
11
{
12
    /**
13
     * @param Message $message
14
     * @return mixed
15
     */
16
    public function handle(Message $message)
17
    {
18
        $text = $message->escaped_text;
19
20
        if (preg_match('/^(@.*?\s)?(?:оформи\sкод|код\sоформи).*?$/isu', $text)) {
21
22
            $hasMentions = count($message->mentions);
23
            $mention = null;
24
25 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...
26
                $mention = $message->mentions[0]->login === \Auth::user()->login
27
                    ? $message->user
28
                    : $message->mentions[0];
29
            }
30
31
            $answer = $mention
32
                ? \Lang::get('markdown.personal', [
33
                    'user'  => $mention->login,
34
                ])
35
                : \Lang::get('markdown.common');
36
37
            $message->italic($answer);
38
39
            return null;
40
        }
41
42
        return $message;
43
    }
44
}
45