Completed
Push — master ( 3723ad...8fd218 )
by WEBEWEB
01:56
created

AbstractQueryBuilder   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 12
lcom 2
cbo 1
dl 0
loc 117
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getField() 0 3 1
A getId() 0 3 1
A getInput() 0 3 1
A getType() 0 3 1
A setField() 0 4 1
A setId() 0 4 1
A setInput() 0 7 2
A setType() 0 7 3
1
<?php
2
3
/*
4
 * This file is part of the jquery-querybuilder-bundle package.
5
 *
6
 * (c) 2017 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\JQuery\QueryBuilderBundle\Model;
13
14
use InvalidArgumentException;
15
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderInputInterface;
16
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderTypeInterface;
17
18
/**
19
 * Abstract QueryBuilder.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\JQuery\QueryBuilderBundle\Model
23
 * @abstract
24
 */
25
abstract class AbstractQueryBuilder implements QueryBuilderInputInterface, QueryBuilderTypeInterface {
26
27
    /**
28
     * Field.
29
     *
30
     * @var string|null
31
     */
32
    private $field;
33
34
    /**
35
     * Id.
36
     *
37
     * @var string|null
38
     */
39
    private $id;
40
41
    /**
42
     * Input.
43
     *
44
     * @var string|null
45
     */
46
    private $input;
47
48
    /**
49
     * Type.
50
     *
51
     * @var string|null
52
     */
53
    private $type;
54
55
    /**
56
     * Constructor.
57
     */
58
    protected function __construct() {
59
        // NOTHING TO TO
60
    }
61
62
    /**
63
     * {@inheritDoc}
64
     */
65
    public function getField(): ?string {
66
        return $this->field;
67
    }
68
69
    /**
70
     * {@inheritDoc}
71
     */
72
    public function getId(): ?string {
73
        return $this->id;
74
    }
75
76
    /**
77
     * {@inheritDoc}
78
     */
79
    public function getInput(): ?string {
80
        return $this->input;
81
    }
82
83
    /**
84
     * {@inheritDoc}
85
     */
86
    public function getType(): ?string {
87
        return $this->type;
88
    }
89
90
    /**
91
     * Set the field.
92
     *
93
     * @param string|null $field The field.
94
     * @return AbstractQueryBuilder Returns this QueryBuilder.
95
     */
96
    public function setField(?string $field): AbstractQueryBuilder {
97
        $this->field = $field;
98
        return $this;
99
    }
100
101
    /**
102
     * Set the id.
103
     *
104
     * @param string|null $id The id.
105
     * @return AbstractQueryBuilder Returns this QueryBuilder.
106
     */
107
    public function setId(?string $id): AbstractQueryBuilder {
108
        $this->id = $id;
109
        return $this;
110
    }
111
112
    /**
113
     * Set the input.
114
     *
115
     * @param string|null $input The input.
116
     * @return AbstractQueryBuilder Returns this QueryBuilder.
117
     * @throws InvalidArgumentException Throws an invalid argument exception if the input is invalid.
118
     */
119
    public function setInput(?string $input): AbstractQueryBuilder {
120
        if (false === in_array($input, QueryBuilderEnumerator::enumInputs())) {
121
            throw new InvalidArgumentException(sprintf('The input "%s" is invalid', $input));
122
        }
123
        $this->input = $input;
124
        return $this;
125
    }
126
127
    /**
128
     * Set the type.
129
     *
130
     * @param string|null $type The type.
131
     * @return AbstractQueryBuilder Returns this QueryBuilder.
132
     * @throws InvalidArgumentException Throws an invalid argument exception if the type is invalid.
133
     */
134
    public function setType(?string $type): AbstractQueryBuilder {
135
        if (null !== $type && false === in_array($type, QueryBuilderEnumerator::enumTypes())) {
136
            throw new InvalidArgumentException(sprintf('The type "%s" is invalid', $type));
137
        }
138
        $this->type = $type;
139
        return $this;
140
    }
141
}
142