1 | <?php |
||
20 | abstract class AbstractMessageResultCollection implements MessageResultCollectionInterface |
||
21 | { |
||
22 | protected array $messageResults = []; |
||
|
|||
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 |