MessageBag::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
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 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\Analyzer;
15
16
use ArrayIterator;
17
use Countable;
18
use IteratorAggregate;
19
use JsonSerializable;
20
use Traversable;
21
22
class MessageBag implements JsonSerializable, IteratorAggregate, Countable
23
{
24
    /**
25
     * @var Message[]
26
     */
27
    private $messages = [];
28
29
    /**
30
     * Adds a message to the message bag.
31
     */
32
    public function add(Message $message): void
33
    {
34
        $this->messages[] = $message;
35
    }
36
37
    /**
38
     * Returns all messages.
39
     *
40
     * @return Message[]
41
     */
42
    public function all(): array
43
    {
44
        return $this->messages;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function jsonSerialize(): array
51
    {
52
        return array_values($this->messages);
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function count(): int
59
    {
60
        return \count($this->messages);
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function getIterator(): Traversable
67
    {
68
        return new ArrayIterator($this->messages);
69
    }
70
}
71