Passed
Push — master ( 2d425f...eb03d1 )
by Jan
04:57 queued 10s
created

EventCommentHelper::getMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4
 *
5
 * Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as published
9
 * by the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
namespace App\Services\LogSystem;
22
23
24
class EventCommentHelper
25
{
26
    protected const MAX_MESSAGE_LENGTH = 255;
27
28
    protected $message;
29
30
    public function __construct()
31
    {
32
        $message = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $message is dead and can be removed.
Loading history...
33
    }
34
35
    /**
36
     * Set the message that will be saved for all ElementEdited/Created/Deleted messages during the next flush.
37
     * Set to null if no message should be shown.
38
     * After the flush this message is cleared.
39
     * @param  string|null  $message
40
     */
41
    public function setMessage(?string $message): void
42
    {
43
        //Restrict the length of the string
44
        $this->message = mb_strimwidth($message, 0, self::MAX_MESSAGE_LENGTH, '...');
45
    }
46
47
    /**
48
     * Returns the currently set message, or null if no message is set yet.
49
     * @return string|null
50
     */
51
    public function getMessage(): ?string
52
    {
53
        return $this->message;
54
    }
55
56
    /**
57
     * Clear the currently set message.
58
     */
59
    public function clearMessage(): void
60
    {
61
        $this->message = null;
62
    }
63
64
    /**
65
     * Check if a message is currently set.
66
     * @return bool
67
     */
68
    public function isMessageSet(): bool
69
    {
70
        return is_string($this->message);
71
    }
72
}