Completed
Push — master ( 72cf95...b4fc03 )
by Artem
08:38
created

AbstractMessageResultCollection   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 0
dl 0
loc 103
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 4 1
A next() 0 4 1
A key() 0 4 1
A valid() 0 6 2
A rewind() 0 4 1
A count() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 2
A offsetUnset() 0 4 1
A offsetSet() 0 20 3
1
<?php
2
/*
3
 * This file is part of the FirebaseCloudMessagingBundle
4
 *
5
 * (c) Artem Henvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Fresh\FirebaseCloudMessagingBundle\Response\MessageResult\Collection;
14
15
/**
16
 * Class AbstractMessageResultCollection.
17
 *
18
 * @author Artem Henvald <[email protected]>
19
 */
20
abstract class AbstractMessageResultCollection implements MessageResultCollectionInterface
21
{
22
    /** @var array */
23
    protected $messageResults = [];
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function current()
29
    {
30
        return \current($this->messageResults);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function next()
37
    {
38
        return \next($this->messageResults);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function key()
45
    {
46
        return \key($this->messageResults);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function valid()
53
    {
54
        $key = \key($this->messageResults);
55
56
        return null !== $key && false !== $key;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function rewind()
63
    {
64
        \reset($this->messageResults);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function count()
71
    {
72
        return \count($this->messageResults);
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function offsetExists($offset)
79
    {
80
        return isset($this->messageResults[$offset]);
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function offsetGet($offset)
87
    {
88
        return isset($this->messageResults[$offset]) ? $this->messageResults[$offset] : null;
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function offsetUnset($offset)
95
    {
96
        unset($this->messageResults[$offset]);
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function offsetSet($offset, $value)
103
    {
104
        $supportedMessageResult = $this->getSupportedMessageResultType();
105
        if (!$value instanceof $supportedMessageResult) {
106
            throw new \Exception(
107
                \sprintf(
108
                    '%s does not support message result of %s. The only supported class is %s',
109
                    static::class,
110
                    \get_class($value),
111
                    $supportedMessageResult
112
                )
113
            );
114
        }
115
116
        if (\is_null($offset)) {
117
            $this->messageResults[] = $value;
118
        } else {
119
            $this->messageResults[$offset] = $value;
120
        }
121
    }
122
}
123