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
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* DeleteContract Data Contract. |
16
|
|
|
*/ |
17
|
|
|
class DeleteContract extends Contract |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Column filter. |
22
|
|
|
* |
23
|
|
|
* @var ColumnFilter |
24
|
|
|
*/ |
25
|
|
|
private $filter; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Sets the input values. |
29
|
|
|
* |
30
|
|
|
* @param string $rootSchemaName The name of the root schema object. |
31
|
|
|
*/ |
32
|
7 |
|
public function __construct($rootSchemaName) |
33
|
|
|
{ |
34
|
7 |
|
parent::__construct([ |
35
|
7 |
|
'rootSchemaName' => $rootSchemaName, |
36
|
7 |
|
'operationType' => Contract::DELETE, |
37
|
7 |
|
'contractType' => Contract::DELETE_QUERY, |
38
|
|
|
]); |
39
|
7 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Adding query filter to contract. |
43
|
|
|
* |
44
|
|
|
* @param ColumnFilter $columnFilter Column filter. |
45
|
|
|
* |
46
|
|
|
* @return self |
47
|
|
|
*/ |
48
|
2 |
|
public function addFilter(ColumnFilter $columnFilter) |
49
|
|
|
{ |
50
|
2 |
|
$this->filter = $columnFilter; |
51
|
2 |
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns data as an associative array. |
56
|
|
|
* |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
2 |
|
public function toArray() |
60
|
|
|
{ |
61
|
2 |
|
$filter = []; |
62
|
2 |
|
if (!empty($this->filter)) { |
63
|
1 |
|
$filter = $this->filter->toArray(); |
64
|
|
|
} |
65
|
|
|
return [ |
66
|
2 |
|
'RootSchemaName' => $this->getRootSchemaName(), |
67
|
2 |
|
'OperationType' => $this->getOperationType(), |
68
|
2 |
|
'Filters' => $filter, |
69
|
|
|
]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Validates contract data, throws an exception in case of an error. |
74
|
|
|
* |
75
|
|
|
* @throws ValidateException |
76
|
|
|
*/ |
77
|
2 |
View Code Duplication |
public function validate() |
|
|
|
|
78
|
|
|
{ |
79
|
2 |
|
if ((3 != $this->getOperationType()) || empty($this->filter)) { |
80
|
1 |
|
throw new ValidateException('Invalid contract arguments.'); |
81
|
|
|
} |
82
|
1 |
|
$this->filter->validate(); |
83
|
1 |
|
} |
84
|
|
|
} |
85
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.