Passed
Push — master ( 7f9295...bd7035 )
by Oss
01:56
created

DeleteContract   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 19
dl 0
loc 78
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 3
A __construct() 0 6 1
A addFilter() 0 4 1
A toArray() 0 10 2
A getResponse() 0 3 1
1
<?php
2
/**
3
 * @category    Brownie/BpmOnline
4
 * @author      Brownie <[email protected]>
5
 * @license     https://opensource.org/licenses/MIT
6
 */
7
8
namespace Brownie\BpmOnline\DataService\Contract;
9
10
use Brownie\BpmOnline\DataService\Contract;
11
use Brownie\BpmOnline\DataService\Column\ColumnFilter;
12
use Brownie\BpmOnline\Exception\ValidateException;
13
use Brownie\BpmOnline\DataService\Response\DeleteContract as ResponseDeleteContract;
14
15
/**
16
 * DeleteContract Data Contract.
17
 */
18
class DeleteContract extends Contract
19
{
20
21
    /**
22
     * Column filter.
23
     *
24
     * @var ColumnFilter
25
     */
26
    private $filter;
27
28
    /**
29
     * Sets the input values.
30
     *
31
     * @param string $rootSchemaName The name of the root schema object.
32
     */
33 8
    public function __construct($rootSchemaName)
34
    {
35 8
        parent::__construct([
36 8
            'rootSchemaName' => $rootSchemaName,
37 8
            'operationType' => Contract::DELETE,
38 8
            'contractType' => Contract::DELETE_QUERY,
39
        ]);
40 8
    }
41
42
    /**
43
     * Adding query filter to contract.
44
     *
45
     * @param ColumnFilter $columnFilter Column filter.
46
     *
47
     * @return self
48
     */
49 2
    public function addFilter(ColumnFilter $columnFilter)
50
    {
51 2
        $this->filter = $columnFilter;
52 2
        return $this;
53
    }
54
55
    /**
56
     * Returns data as an associative array.
57
     *
58
     * @return array
59
     */
60 2
    public function toArray()
61
    {
62 2
        $filter = [];
63 2
        if (!empty($this->filter)) {
64 1
            $filter = $this->filter->toArray();
65
        }
66
        return [
67 2
            'RootSchemaName' => $this->getRootSchemaName(),
68 2
            'OperationType' => $this->getOperationType(),
69 2
            'Filters' => $filter,
70
        ];
71
    }
72
73
    /**
74
     * Validates contract data, throws an exception in case of an error.
75
     *
76
     * @throws ValidateException
77
     */
78 2
    public function validate()
79
    {
80 2
        if ((3 != $this->getOperationType()) || empty($this->filter)) {
81 1
            throw new ValidateException('Invalid contract arguments.');
82
        }
83 1
        $this->filter->validate();
84 1
    }
85
86
    /**
87
     * Returns the response of the performance contract.
88
     *
89
     * @param string    $rawResponse    Raw response.
90
     *
91
     * @return ResponseDeleteContract
92
     */
93 1
    public function getResponse($rawResponse)
94
    {
95 1
        return new ResponseDeleteContract($rawResponse);
96
    }
97
}
98