Completed
Push — master ( fd5325...d7e193 )
by Schlaefer
05:54 queued 03:00
created

Notifications   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 27 5
A getAll() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Saito - The Threaded Web Forum
7
 *
8
 * @copyright Copyright (c) the Saito Project Developers
9
 * @link https://github.com/Schlaefer/Saito
10
 * @license http://opensource.org/licenses/MIT
11
 */
12
13
namespace Saito\JsData;
14
15
class Notifications
16
{
17
    protected $notifications = [];
18
19
    /**
20
     * Add message
21
     *
22
     * @param string $message message
23
     * @param array|null $options options
24
     * @return void
25
     */
26
    public function add(string $message, ?array $options = []): void
27
    {
28
        $defaults = [
29
            'type' => 'notice',
30
            'channel' => 'notification'
31
        ];
32
        $options = array_merge($defaults, $options);
33
34
        if (!is_array($message)) {
35
            $message = [$message];
36
        }
37
38
        foreach ($message as $m) {
39
            $nm = [
40
                'message' => $m,
41
                'type' => $options['type'],
42
                'channel' => $options['channel']
43
            ];
44
            if (isset($options['title'])) {
45
                $nm['title'] = $options['title'];
46
            }
47
            if (isset($options['element'])) {
48
                $nm['element'] = $options['element'];
49
            }
50
            $this->notifications[] = $nm;
51
        }
52
    }
53
54
    /**
55
     * Gets all messages
56
     *
57
     * @return array All messages.
58
     */
59
    public function getAll(): array
60
    {
61
        return $this->notifications;
62
    }
63
}
64