Completed
Push — master ( 74c577...c1ce98 )
by Kirill
06:10
created

Message   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A getWordsAttribute() 0 15 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * This file is part of GitterBot package.
5
 *
6
 * @author Serafim <[email protected]>
7
 * @date 28.03.2016 14:06
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
namespace Domains\Message;
13
14
use Carbon\Carbon;
15
use Core\Mappers\Message\MessageMapper;
16
use Domains\Analyser\UrlFinder;
17
18
/**
19
 * Class Message
20
 * @package Domains\Message
21
 *
22
 * @property-read $text
23
 * @property-read Carbon $created_at
24
 * @property-read Carbon $updated_at
25
 * @property-read array $words
26
 */
27
class Message extends MessageMapper
28
{
29
    /**
30
     * @return string
31
     */
32
    public function getId()
33
    {
34
        return $this->id;
35
    }
36
37
    /**
38
     * @return mixed
39
     */
40
    public function getWordsAttribute()
41
    {
42
        $text = $this->text;
43
44
        $text = preg_replace('/```.*?```/su', '', $text);
45
        $text = preg_replace('/`.*?`/su', '', $text);
46
        $text = preg_replace(UrlFinder::getPattern(), '', $text);
47
        $text = preg_replace('/@[a-z0-9_@]+/iu', '', $text);
48
49
        preg_match_all('/\w+/iu', $text, $words, PREG_PATTERN_ORDER);
50
51
        return array_map(function ($word) {
52
            return mb_strtolower($word);
53
        }, $words[0]);
54
    }
55
}
56