Test Failed
Push — master ( 475bfc...ca0e1d )
by Oss
05:46
created

DeleteContract   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 10.29 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 7
loc 68
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A addFilter() 0 5 1
A toArray() 0 12 2
A validate() 7 7 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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