MessageBag   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 49
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A all() 0 4 1
A jsonSerialize() 0 4 1
A count() 0 4 1
A getIterator() 0 4 1
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