TransactionOptions   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setPeers() 0 4 1
A addPeers() 0 3 1
A hasPeers() 0 3 1
A getPeers() 0 3 1
A withPeers() 0 6 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\Transaction;
22
23
use AmericanExpress\HyperledgerFabricClient\Options\AbstractOptions;
24
use AmericanExpress\HyperledgerFabricClient\Peer\PeerCollectionInterface;
25
use AmericanExpress\HyperledgerFabricClient\Peer\PeerInterface;
26
27
class TransactionOptions extends AbstractOptions implements PeerCollectionInterface
28
{
29
    /**
30
     * @var PeerInterface[]
31
     */
32
    private $peers = [];
33
34
    /**
35
     * @return PeerInterface[]
36
     */
37 7
    public function getPeers(): array
38
    {
39 7
        return $this->peers;
40
    }
41
42
    /**
43
     * @param PeerInterface[] $peers
44
     * @return void
45
     */
46 4
    public function setPeers(array $peers): void
47
    {
48 4
        $this->peers = [];
49 4
        $this->addPeers(...$peers);
50 4
    }
51
52
    /**
53
     * @param PeerInterface[] ...$peers
54
     * @return void
55
     */
56 6
    public function addPeers(PeerInterface ...$peers): void
57
    {
58 6
        $this->peers = array_merge($this->peers, $peers);
59 6
    }
60
61
    /**
62
     * @return bool
63
     */
64 3
    public function hasPeers(): bool
65
    {
66 3
        return count($this->peers) > 0;
67
    }
68
69
    /**
70
     * @param PeerInterface[] ...$peers
71
     * @return static
72
     * @throws \AmericanExpress\HyperledgerFabricClient\Exception\BadMethodCallException
73
     */
74 1
    public function withPeers(PeerInterface ...$peers): TransactionOptions
75
    {
76 1
        $options = new static();
77 1
        $options->setPeers($peers);
78
79 1
        return $options;
80
    }
81
}
82