AlertPublisher::count()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * AlertPublisher.php
4
 * Definition of class AlertPublisher
5
 *
6
 * Created 31/08/14 07:19
7
 *
8
 * @author Rasanga Perera <[email protected]>
9
 * Copyright (c) 2014, The MIT License (MIT)
10
 */
11
12
namespace Ras\Bundle\FlashAlertBundle\Model;
13
14
15
class AlertPublisher implements \Iterator, \ArrayAccess, \Countable
16
{
17
    /**
18
     * @var array
19
     */
20
    private $alerts;
21
22
    /**
23
     * @param AlertManagerInterface $alertManager
24
     */
25
    public function __construct(AlertManagerInterface $alertManager)
26
    {
27
        $this->alerts = $alertManager->getAlerts();
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function current()
34
    {
35
        return current($this->alerts);
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function next()
42
    {
43
        next($this->alerts);
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function key()
50
    {
51
        return key($this->alerts);
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57
    public function valid()
58
    {
59
        return key($this->alerts) !== null;
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65
    public function rewind()
66
    {
67
        return reset($this->alerts);
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73
    public function offsetExists($offset)
74
    {
75
        return isset($this->alerts[$offset]);
76
    }
77
78
    /**
79
     * @inheritdoc
80
     */
81
    public function offsetGet($offset)
82
    {
83
        return isset($this->alerts[$offset]) ? $this->alerts[$offset] : null;
84
    }
85
86
    /**
87
     * @inheritdoc
88
     */
89
    public function offsetSet($offset, $value)
90
    {
91
        $this->$this->alerts[$offset] = $value;
92
    }
93
94
    /**
95
     * @inheritdoc
96
     */
97
    public function offsetUnset($offset)
98
    {
99
        unset($this->alerts[$offset]);
100
    }
101
102
    /**
103
     * @inheritdoc
104
     */
105
    public function count()
106
    {
107
        return count($this->alerts);
108
    }
109
}