Notifications::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Rojtjo\Notifier;
4
5
use ArrayIterator;
6
use Countable;
7
use IteratorAggregate;
8
9
class Notifications implements IteratorAggregate, Countable
10
{
11
    /**
12
     * @var Notification[]
13
     */
14
    private $notifications;
15
16
    /**
17
     * @param Notification[] $notifications
18
     */
19 24
    public function __construct(array $notifications = [])
20
    {
21 24
        $this->notifications = $notifications;
22 24
    }
23
24
    /**
25
     * @param array $notifications
26
     * @return Notifications
27
     */
28
    public static function mapFromArray(array $notifications)
29
    {
30 9
        $mapped = array_map(function (array $notification) {
31 6
            return Notification::fromArray($notification);
32 9
        }, $notifications);
33
34 9
        return new Notifications($mapped);
35
    }
36
37
    /**
38
     * @return ArrayIterator
39
     */
40 12
    public function getIterator()
41
    {
42 12
        return new ArrayIterator($this->notifications);
43
    }
44
45
    /**
46
     * @return int
47
     */
48 6
    public function count()
49
    {
50 6
        return count($this->notifications);
51
    }
52
}
53