Main   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 22
dl 0
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B getEventSend() 0 12 7
A delTags() 0 3 1
A getSiteParam() 0 17 2
1
<?php
2
3
namespace Telegram\Send;
4
5
use Bitrix\Main\Diag\Debug;
6
use Bitrix\Main\SiteTable;
7
8
/**
9
 * Class Main
10
 * @package Telegram\Send
11
 */
12
class Main
13
{
14
    /**
15
     * Действие после отправки письма
16
     *
17
     * @param $arFields
18
     * @param $arTemplate
19
     */
20
    public static function getEventSend(&$arFields, &$arTemplate)
21
    {
22
        if ($arFields && $arTemplate && Config::statusModule() == 1) {
23
            if (\in_array($arTemplate['EVENT_NAME'], Config::getMail(), true)) {
24
                try {
25
                    $message = self::delTags($arTemplate['MESSAGE']);
26
                    foreach ($arFields + self::getSiteParam() as $key => $field) {
27
                        $message = preg_replace('/#' . $key . '#/', $field, $message);
28
                    }
29
                    (new Sending)->processMessage($message);
30
                } catch (\Exception $e) {
31
                    Debug::writeToFile($e->getMessage(), 'getEventSend', 'telegram-log');
32
                }
33
            }
34
        }
35
    }
36
37
    /**
38
     * Удаление html тегов из письма
39
     *
40
     * @param $text
41
     *
42
     * @return mixed
43
     */
44
    public static function delTags($text)
45
    {
46
        return str_replace('&nbsp;', ' ', preg_replace('/\s{2,}/', "\n", strip_tags($text)));
47
    }
48
49
    /**
50
     * Получение стандартных полей письма
51
     * @return array
52
     */
53
    public static function getSiteParam():array
54
    {
55
        $defaultParam = [];
56
        $getParam = SiteTable::getList([
57
            'select' => ['EMAIL', 'NAME', 'SERVER_NAME'],
58
            'filter' => ['ACTIVE' => 'Y']
59
        ]);
60
        $siteParam = $getParam->fetch();
61
        if ($siteParam) {
62
            $defaultParam = [
63
                'DEFAULT_EMAIL_FROM' => $siteParam['EMAIL'],
64
                'SITE_NAME'          => $siteParam['NAME'],
65
                'SERVER_NAME'        => $siteParam['SERVER_NAME']
66
            ];
67
        }
68
69
        return $defaultParam;
70
    }
71
} //
72