Passed
Push — deprecate/getLogEntriesForPage... ( 209510...c5a454 )
by Tomas Norre
09:05 queued 05:28
created

MessageUtility::addNoticeMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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
class MessageUtility
27
{
28
    /**
29
     * Add notice message to the user interface.
30
     */
31 2
    public static function addNoticeMessage(string $message): void
32
    {
33 2
        self::addMessage($message, FlashMessage::NOTICE);
34 2
    }
35
36
    /**
37
     * Add error message to the user interface.
38
     */
39 2
    public static function addErrorMessage(string $message): void
40
    {
41 2
        self::addMessage($message, FlashMessage::ERROR);
42 2
    }
43
44
    /**
45
     * Add error message to the user interface.
46
     */
47 2
    public static function addWarningMessage(string $message): void
48
    {
49 2
        self::addMessage($message, FlashMessage::WARNING);
50 2
    }
51
52
    /**
53
     * This method is used to add a message to the internal queue
54
     *
55
     * @param string $message the message itself
56
     * @param int $severity message level (0 = success (default), -1 = info, -2 = notice, 1 = warning, 2 = error)
57
     */
58 6
    private static function addMessage(string $message, int $severity = FlashMessage::OK): void
59
    {
60 6
        $message = GeneralUtility::makeInstance(
61 6
            FlashMessage::class,
62 6
            $message,
63 6
            '',
64 6
            $severity
65
        );
66
67
        /** @var FlashMessageService $flashMessageService */
68 6
        $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
69 6
        $flashMessageService->getMessageQueueByIdentifier()->addMessage($message);
70 6
    }
71
}
72