UnaryCallResolver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
ccs 12
cts 12
cp 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveMany() 0 7 1
A resolveOne() 0 11 2
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\Peer;
22
23
use AmericanExpress\HyperledgerFabricClient\Exception\RuntimeException;
24
use AmericanExpress\HyperledgerFabricClient\Proposal\Response;
25
use AmericanExpress\HyperledgerFabricClient\Proposal\ResponseCollection;
26
use Grpc\UnaryCall;
27
use Hyperledger\Fabric\Protos\Peer\ProposalResponse;
28
use function igorw\get_in;
0 ignored issues
show
introduced by
The function igorw\get_in was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
29
30
final class UnaryCallResolver implements UnaryCallResolverInterface
31
{
32
    /**
33
     * @param UnaryCall $call
34
     * @return Response
35
     */
36 5
    public function resolveOne(UnaryCall $call): Response
37
    {
38 5
        [$proposalResponse, $status] = $call->wait();
39
40 5
        if ($proposalResponse instanceof ProposalResponse) {
41 3
            return Response::fromProposalResponse($proposalResponse);
42
        }
43
44 3
        $status = (array) $status;
45 3
        return Response::fromException(
46 3
            new RuntimeException(get_in($status, ['details']), get_in($status, ['code']))
0 ignored issues
show
Bug introduced by
get_in($status, array('details')) of type array is incompatible with the type string expected by parameter $message of AmericanExpress\Hyperled...xception::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
            new RuntimeException(/** @scrutinizer ignore-type */ get_in($status, ['details']), get_in($status, ['code']))
Loading history...
Bug introduced by
get_in($status, array('code')) of type array is incompatible with the type integer expected by parameter $code of AmericanExpress\Hyperled...xception::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
            new RuntimeException(get_in($status, ['details']), /** @scrutinizer ignore-type */ get_in($status, ['code']))
Loading history...
47
        );
48
    }
49
50
    /**
51
     * @param UnaryCall|UnaryCall[] ...$calls
52
     * @return ResponseCollection
53
     */
54 3
    public function resolveMany(UnaryCall ...$calls): ResponseCollection
55
    {
56 3
        $peer = $this;
57
58 3
        return new ResponseCollection(\array_map(function (UnaryCall $call) use ($peer) {
59 3
            return $peer->resolveOne($call);
60 3
        }, $calls));
61
    }
62
}
63