Completed
Push — master ( a1f3ed...74c577 )
by Kirill
02:49
created

InlineDataMiddleware   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 4
1
<?php
2
namespace Domains\Bot\Middlewares;
3
4
use Domains\Message;
5
use Interfaces\Gitter\Middleware\MiddlewareInterface;
6
7
/**
8
 * Class InlineDataMiddleware
9
 */
10
class InlineDataMiddleware implements MiddlewareInterface
11
{
12
    /**
13
     * @param Message $message
14
     * @return mixed
15
     */
16
    public function handle(Message $message)
17
    {
18
        $isImage = preg_match(
19
            '/[^`]http(?:s)?:\/\/.*?\.(?:jpg|png|jpeg|svg|bmp)/iu'
20
        , ' ' . $message->text);
21
22
        $isVideo = preg_match(
23
            '/[^`]http(?:s)?:\/\/(?:www\.)?(?:youtube\.com|youtu\.be).*?/iu'
24
        , ' ' . $message->text);
25
26
        if (($isImage || $isVideo) && $message->user->login !== \Auth::user()->login) {
27
            $answer = \Lang::get('gitter.inline', [
28
                'user' => $message->user->login
29
            ]);
30
            $message->italic($answer);
31
        }
32
33
        return $message;
34
    }
35
}
36