ExceptionCollection   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 59
ccs 17
cts 17
cp 1
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 4 1
A getFirst() 0 4 2
A add() 0 9 2
A getIterator() 0 4 1
A __construct() 0 4 2
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCache package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCache\Exception;
13
14
/**
15
 * A collection of exceptions that might occur during the flush operation of a
16
 * ProxyClientInterface implementation.
17
 */
18
class ExceptionCollection extends \Exception implements \IteratorAggregate, \Countable, HttpCacheException
19
{
20
    private $exceptions = [];
21
22 40
    public function __construct(array $exceptions = [])
23
    {
24 40
        foreach ($exceptions as $exception) {
25 1
            $this->add($exception);
26
        }
27 40
    }
28
29
    /**
30
     * Add an exception to the collection.
31
     *
32
     * @return $this
33
     */
34 8
    public function add(\Exception $e)
35
    {
36 8
        if (!$this->message) {
37 8
            $this->message = $e->getMessage();
38
        }
39
40 8
        $this->exceptions[] = $e;
41
42 8
        return $this;
43
    }
44
45
    /**
46
     * Get first exception in collection or null, if there is none.
47
     *
48
     * @return \Exception|null
49
     */
50 7
    public function getFirst()
51
    {
52 7
        if ($this->count() > 0) {
53 7
            return $this->exceptions[0];
54
        }
55 1
    }
56
57
    /**
58
     * Get exception iterator.
59
     *
60
     * @return \ArrayIterator
61
     */
62
    #[\ReturnTypeWillChange]
63 3
    public function getIterator()
64
    {
65 3
        return new \ArrayIterator($this->exceptions);
66
    }
67
68
    /**
69
     * Get number of exceptions in collection.
70
     *
71
     * @return int
72
     */
73
    #[\ReturnTypeWillChange]
74 38
    public function count()
75
    {
76 38
        return count($this->exceptions);
77
    }
78
}
79