BatchContract::setContracts()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @category    Brownie/BpmOnline
5
 * @author      Brownie <[email protected]>
6
 * @license     https://opensource.org/licenses/MIT
7
 */
8
9
namespace Brownie\BpmOnline\DataService\Response;
10
11
use Brownie\BpmOnline\DataService\Contract;
12
use Brownie\BpmOnline\DataService\Response;
13
14
use Brownie\BpmOnline\Exception\ValidateException;
15
/**
16
 * The response to the execution of the contract BatchContract.
17
 */
18
class BatchContract extends Response
19
{
20
21
    /**
22
     * Contracts.
23
     *
24
     * @var Contract[]
25
     */
26
    private $contracts = [];
27
28
    /**
29
     * Sets the input values.
30
     *
31
     * @param string    $rawResponse    Raw response.
32
     * @param array     $contracts      Contracts.
33
     */
34 2
    public function __construct($rawResponse, $contracts = [])
35
    {
36 2
        parent::__construct($rawResponse);
37 2
        $this->setContracts($contracts);
38 2
    }
39
40
    /**
41
     * Sets contracts.
42
     *
43
     * @param array $contracts Contracts
44
     *
45
     * @return self
46
     */
47 2
    private function setContracts(array $contracts)
48
    {
49 2
        $this->contracts = $contracts;
50 2
        return $this;
51
    }
52
53
    /**
54
     * Returns contracts.
55
     *
56
     * @return Contract[]
57
     */
58 1
    private function getContracts()
59
    {
60 1
        return $this->contracts;
61
    }
62
63
    /**
64
     * Returns responses.
65
     *
66
     * @return Response[]
67
     *
68
     * @throws ValidateException
69
     */
70 1
    public function getContractsResponse()
71
    {
72 1
        $responses = [];
73 1
        $queryResults = $this->getRequestValue('queryResults');
74
        /**
75
         * @var Contract $contract
76
         */
77 1
        foreach ($this->getContracts() as $index => $contract) {
78 1
            $responses[] = $contract->getResponse(json_encode($queryResults[$index]));
79
        }
80 1
        return $responses;
81
    }
82
}
83