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

InlineDataMiddleware::handle()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.2
cc 4
eloc 12
nc 2
nop 1
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