ResponseCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
ccs 13
cts 13
cp 1
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getProposalResponses() 0 5 1
A getExceptions() 0 5 1
A hasProposalResponses() 0 3 1
A __construct() 0 3 1
A hasExceptions() 0 3 1
1
<?php
2
3
/**
4
 * Copyright 2017 American Express Travel Related Services Company, Inc.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15
 * or implied. See the License for the specific language governing
16
 * permissions and limitations under the License.
17
 */
18
19
declare(strict_types=1);
20
21
namespace AmericanExpress\HyperledgerFabricClient\Proposal;
22
23
use Hyperledger\Fabric\Protos\Peer\ProposalResponse;
24
25
class ResponseCollection
26
{
27
    /**
28
     * @var Response[]
29
     */
30
    private $responses;
31
32
    /**
33
     * ProposalResponseCollection constructor.
34
     * @param mixed[] $responses
35
     */
36 4
    public function __construct(array $responses = [])
37
    {
38 4
        $this->responses = $responses;
39 4
    }
40
41
    /**
42
     * @return ProposalResponse[]
43
     */
44
    public function getProposalResponses(): array
45
    {
46 3
        return \array_filter(\array_map(function (Response $response) {
47 2
            return $response->getProposalResponse();
48 3
        }, $this->responses));
49
    }
50
51
    /**
52
     * @return bool
53
     */
54 3
    public function hasProposalResponses(): bool
55
    {
56 3
        return \count($this->getProposalResponses()) > 0;
57
    }
58
59
    /**
60
     * @return \Exception[]
61
     */
62
    public function getExceptions(): array
63
    {
64 3
        return \array_filter(\array_map(function (Response $response) {
65 2
            return $response->getException();
66 3
        }, $this->responses));
67
    }
68
69
    /**
70
     * @return bool
71
     */
72 3
    public function hasExceptions(): bool
73
    {
74 3
        return \count($this->getExceptions()) > 0;
75
    }
76
}
77