Completed
Push — master ( 611a4d...0d4705 )
by Artem
11:18 queued 04:23
created

AbstractMessageResultCollection::offsetSet()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 3
nc 3
nop 2
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
    protected array $messageResults = [];
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function current()
28
    {
29
        return \current($this->messageResults);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function next()
36
    {
37
        return \next($this->messageResults);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function key()
44
    {
45
        return \key($this->messageResults);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function valid(): bool
52
    {
53
        $key = \key($this->messageResults);
54
55
        return null !== $key && false !== $key;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function rewind(): void
62
    {
63
        \reset($this->messageResults);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function count()
70
    {
71
        return \count($this->messageResults);
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function offsetExists($offset): bool
78
    {
79
        return isset($this->messageResults[$offset]);
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function offsetGet($offset)
86
    {
87
        return $this->messageResults[$offset] ?? null;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function offsetUnset($offset): void
94
    {
95
        unset($this->messageResults[$offset]);
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function offsetSet($offset, $value): void
102
    {
103
        $supportedMessageResult = $this->getSupportedMessageResultType();
104
        if (!$value instanceof $supportedMessageResult) {
105
            $exceptionMessage = \sprintf(
106
                '%s does not support message result of %s. The only supported class is %s',
107
                static::class,
108
                \get_class($value),
109
                $supportedMessageResult
110
            );
111
112
            throw new \Exception($exceptionMessage);
113
        }
114
115
        if (null === $offset) {
116
            $this->messageResults[] = $value;
117
        } else {
118
            $this->messageResults[$offset] = $value;
119
        }
120
    }
121
}
122