Failed Conditions
Push — master ( 6560de...8483ce )
by Florent
05:17
created

MessageBag::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Component\KeyManagement\KeyAnalyzer;
15
16
/**
17
 * Class MessageBag.
18
 */
19
final class MessageBag implements \JsonSerializable, \ArrayAccess, \IteratorAggregate, \Countable
20
{
21
    /**
22
     * @var Message[]
23
     */
24
    private $messages = [];
25
26
    /**
27
     * @param Message $message
28
     *
29
     * @return MessageBag
30
     */
31
    public function add(Message $message): MessageBag
32
    {
33
        $this->messages[] = $message;
34
35
        return $this;
36
    }
37
38
    /**
39
     * @return Message[]
40
     */
41
    public function all(): array
42
    {
43
        return $this->messages;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function jsonSerialize()
50
    {
51
        return array_values($this->messages);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function offsetExists($offset)
58
    {
59
        return isset($this->messages[$offset]);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function offsetGet($offset)
66
    {
67
        return isset($this->messages[$offset]) ? $this->messages[$offset] : null;
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function offsetSet($offset, $value)
74
    {
75
        $this->messages[$offset] = $value;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function offsetUnset($offset)
82
    {
83
        unset($this->messages[$offset]);
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function count()
90
    {
91
        return count($this->messages);
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function getIterator()
98
    {
99
        return new \ArrayIterator($this->messages);
100
    }
101
}
102