MessageUtility   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 44
ccs 17
cts 17
cp 1
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addMessage() 0 12 1
A addNoticeMessage() 0 3 1
A addErrorMessage() 0 3 1
A addWarningMessage() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AOE\Crawler\Utility;
6
7
/*
8
 * (c) 2020 AOE GmbH <[email protected]>
9
 *
10
 * This file is part of the TYPO3 Crawler Extension.
11
 *
12
 * It is free software; you can redistribute it and/or modify it under
13
 * the terms of the GNU General Public License, either version 2
14
 * of the License, or any later version.
15
 *
16
 * For the full copyright and license information, please read the
17
 * LICENSE.txt file that was distributed with this source code.
18
 *
19
 * The TYPO3 project - inspiring people to share!
20
 */
21
22
use TYPO3\CMS\Core\Messaging\FlashMessage;
23
use TYPO3\CMS\Core\Messaging\FlashMessageService;
24
use TYPO3\CMS\Core\Utility\GeneralUtility;
25
26
/**
27
 * @internal since v9.2.5
28
 */
29
class MessageUtility
30
{
31
    /**
32
     * Add notice message to the user interface.
33
     */
34 1
    public static function addNoticeMessage(string $message): void
35
    {
36 1
        self::addMessage($message, FlashMessage::NOTICE);
37 1
    }
38
39
    /**
40
     * Add error message to the user interface.
41
     */
42 1
    public static function addErrorMessage(string $message): void
43
    {
44 1
        self::addMessage($message, FlashMessage::ERROR);
45 1
    }
46
47
    /**
48
     * Add error message to the user interface.
49
     */
50 2
    public static function addWarningMessage(string $message): void
51
    {
52 2
        self::addMessage($message, FlashMessage::WARNING);
53 2
    }
54
55
    /**
56
     * This method is used to add a message to the internal queue
57
     *
58
     * @param string $message the message itself
59
     * @param int $severity message level (0 = success (default), -1 = info, -2 = notice, 1 = warning, 2 = error)
60
     */
61 4
    private static function addMessage(string $message, int $severity = FlashMessage::OK): void
62
    {
63 4
        $message = GeneralUtility::makeInstance(
64 4
            FlashMessage::class,
65 4
            $message,
66 4
            '',
67 4
            $severity
68
        );
69
70
        /** @var FlashMessageService $flashMessageService */
71 4
        $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
72 4
        $flashMessageService->getMessageQueueByIdentifier()->addMessage($message);
73 4
    }
74
}
75