Completed
Pull Request — master (#366)
by Beñat
14:40
created

Notifications   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 4 1
A of() 0 8 2
A count() 0 4 1
A getIterator() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\Notifier\Domain\Model\Inbox;
16
17
class Notifications implements \IteratorAggregate
18
{
19
    private $notifications;
20
21
    public function __construct(Notification ...$notifications)
22
    {
23
        $this->notifications = $notifications;
24
    }
25
26
    public function add(Notification $notification) : void
27
    {
28
        $this->notifications[] = $notification;
29
    }
30
31
    public function of(int $index) : Notification
32
    {
33
        if (!isset($this->notifications[$index])) {
34
            throw new NotificationDoesNotExist();
35
        }
36
37
        return $this->notifications[$index];
38
    }
39
40
    public function count() : int
41
    {
42
        return count($this->notifications);
43
    }
44
45
    public function getIterator() : \ArrayIterator
46
    {
47
        return new \ArrayIterator($this->notifications);
48
    }
49
}
50