TelegramMessageFormatter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 3
eloc 13
c 3
b 1
f 0
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getExceptionMessage() 0 19 3
1
<?php
2
3
namespace Skater4\LaravelSentryNotifications\Services\Messengers\Clients\Telegram;
4
5
use Skater4\LaravelSentryNotifications\Services\Messengers\Interfaces\MessageFormatterInterface;
6
use Throwable;
7
8
class TelegramMessageFormatter implements MessageFormatterInterface
9
{
10
    const MESSAGE_LENGTH = 1000;
11
12
    /**
13
     * @param Throwable $e
14
     * @return string
15
     */
16
    public function getExceptionMessage(Throwable $e): string
17
    {
18
        $text = '';
19
20
        if (!empty(config('app.name'))) {
21
            $text .= 'Project URL: ' . '[' . url('/') . '](' . url('/') . ')' . PHP_EOL;
22
        }
23
24
        $text .= 'Env: ' . config('app.env') . PHP_EOL;
25
        $text .= 'Exception: ' . get_class($e) . PHP_EOL;
26
        $text .= '```Error: ' . $e->getMessage() . '```' . PHP_EOL;
27
        $text .= '```Trace: ' . $e->getTraceAsString() . '```' . PHP_EOL;
28
29
        if (mb_strlen($text) > self::MESSAGE_LENGTH) {
30
            $text = mb_substr($text, 0, self::MESSAGE_LENGTH);
31
            $text = rtrim($text) . '...```';
32
        }
33
34
        return $text;
35
    }
36
}
37