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

Notifications::of()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 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