Failed Conditions
Pull Request — user-welcomefix (#623)
by Simon
07:11 queued 03:11
created

RequestQueue::setDomain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\DataObjects;
10
11
use Exception;
12
use Waca\DataObject;
13
use Waca\Exceptions\OptimisticLockFailedException;
14
15
class RequestQueue extends DataObject
16
{
17
    /** @var int */
18
    private $enabled = 0;
19
    /** @var int */
20
    private $isdefault = 0;
21
    /** @var int */
22
    private $domain;
23
    /** @var string */
24
    private $apiname;
25
    /** @var string */
26
    private $displayname;
27
    /** @var string */
28
    private $header;
29
    /** @var string|null */
30
    private $help;
31
    /**
32
     * @var string
33
     * @deprecated Removal due as part of #607
34
     */
35
    private $logname;
36
    /**
37
     * @var string
38
     * @deprecated Removal due as part of #602
39
     */
40
    private $legacystatus;
41
42
43
    public function save()
44
    {
45
        if ($this->isNew()) {
46
            // insert
47
            $statement = $this->dbObject->prepare(<<<SQL
48
                INSERT INTO requestqueue (
49
                    enabled, isdefault, domain, apiname, displayname, header, help, logname, legacystatus
50
                ) VALUES (
51
                    :enabled, :isdefault, :domain, :apiname, :displayname, :header, :help, :logname, :legacystatus
52
                );
53
SQL
54
            );
55
56
            $statement->bindValue(":enabled", $this->enabled);
57
            $statement->bindValue(":isdefault", $this->isdefault);
58
            $statement->bindValue(":domain", $this->domain);
59
            $statement->bindValue(":apiname", $this->apiname);
60
            $statement->bindValue(":displayname", $this->displayname);
61
            $statement->bindValue(":header", $this->header);
62
            $statement->bindValue(":help", $this->help);
63
            $statement->bindValue(":logname", $this->logname);
0 ignored issues
show
Deprecated Code introduced by
The property Waca\DataObjects\RequestQueue::$logname has been deprecated: Removal due as part of #607 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

63
            $statement->bindValue(":logname", /** @scrutinizer ignore-deprecated */ $this->logname);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
64
            $statement->bindValue(":legacystatus", $this->legacystatus);
0 ignored issues
show
Deprecated Code introduced by
The property Waca\DataObjects\RequestQueue::$legacystatus has been deprecated: Removal due as part of #602 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

64
            $statement->bindValue(":legacystatus", /** @scrutinizer ignore-deprecated */ $this->legacystatus);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
65
66
            if ($statement->execute()) {
67
                $this->id = (int)$this->dbObject->lastInsertId();
68
            }
69
            else {
70
                throw new Exception($statement->errorInfo());
0 ignored issues
show
Bug introduced by
$statement->errorInfo() of type array is incompatible with the type string expected by parameter $message of Exception::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

70
                throw new Exception(/** @scrutinizer ignore-type */ $statement->errorInfo());
Loading history...
71
            }
72
        }
73
        else {
74
            $statement = $this->dbObject->prepare(<<<SQL
75
                UPDATE requestqueue SET
76
                    enabled = :enabled,
77
                    isdefault = :isdefault,
78
                    domain = :domain,
79
                    apiname = :apiname,
80
                    displayname = :displayname,
81
                    header = :header,
82
                    help = :help,
83
                    logname = :logname,
84
                    legacystatus = :legacystatus,
85
                
86
                    updateversion = updateversion + 1
87
				WHERE id = :id AND updateversion = :updateversion;
88
SQL
89
            );
90
91
            $statement->bindValue(":enabled", $this->enabled);
92
            $statement->bindValue(":isdefault", $this->isdefault);
93
            $statement->bindValue(":domain", $this->domain);
94
            $statement->bindValue(":apiname", $this->apiname);
95
            $statement->bindValue(":displayname", $this->displayname);
96
            $statement->bindValue(":header", $this->header);
97
            $statement->bindValue(":help", $this->help);
98
            $statement->bindValue(":logname", $this->logname);
0 ignored issues
show
Deprecated Code introduced by
The property Waca\DataObjects\RequestQueue::$logname has been deprecated: Removal due as part of #607 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

98
            $statement->bindValue(":logname", /** @scrutinizer ignore-deprecated */ $this->logname);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
99
            $statement->bindValue(":legacystatus", $this->legacystatus);
0 ignored issues
show
Deprecated Code introduced by
The property Waca\DataObjects\RequestQueue::$legacystatus has been deprecated: Removal due as part of #602 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

99
            $statement->bindValue(":legacystatus", /** @scrutinizer ignore-deprecated */ $this->legacystatus);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
100
101
            $statement->bindValue(':id', $this->id);
102
            $statement->bindValue(':updateversion', $this->updateversion);
103
104
            if (!$statement->execute()) {
105
                throw new Exception($statement->errorInfo());
106
            }
107
108
            if ($statement->rowCount() !== 1) {
109
                throw new OptimisticLockFailedException();
110
            }
111
112
            $this->updateversion++;
113
        }
114
    }
115
116
    /**
117
     * @return bool
118
     */
119
    public function isEnabled(): bool
120
    {
121
        return $this->enabled == 1;
122
    }
123
124
    /**
125
     * @param bool $enabled
126
     */
127
    public function setEnabled(bool $enabled): void
128
    {
129
        $this->enabled = $enabled ? 1 : 0;
130
    }
131
132
    /**
133
     * @return bool
134
     */
135
    public function isDefault(): bool
136
    {
137
        return $this->isdefault == 1;
138
    }
139
140
    /**
141
     * @param bool $isDefault
142
     */
143
    public function setDefault(bool $isDefault): void
144
    {
145
        $this->isdefault = $isDefault ? 1 : 0;
146
    }
147
148
    /**
149
     * @return int
150
     */
151
    public function getDomain(): int
152
    {
153
        return $this->domain;
154
    }
155
156
    /**
157
     * @param int $domain
158
     */
159
    public function setDomain(int $domain): void
160
    {
161
        $this->domain = $domain;
162
    }
163
164
    /**
165
     * @return string
166
     */
167
    public function getApiName(): string
168
    {
169
        return $this->apiname;
170
    }
171
172
    /**
173
     * @param string $apiName
174
     */
175
    public function setApiName(string $apiName): void
176
    {
177
        $this->apiname = $apiName;
178
    }
179
180
    /**
181
     * @return string
182
     */
183
    public function getDisplayName(): string
184
    {
185
        return $this->displayname;
186
    }
187
188
    /**
189
     * @param string $displayName
190
     */
191
    public function setDisplayName(string $displayName): void
192
    {
193
        $this->displayname = $displayName;
194
    }
195
196
    /**
197
     * @return string
198
     */
199
    public function getHeader(): string
200
    {
201
        return $this->header;
202
    }
203
204
    /**
205
     * @param string $header
206
     */
207
    public function setHeader(string $header): void
208
    {
209
        $this->header = $header;
210
    }
211
212
    /**
213
     * @return string|null
214
     */
215
    public function getHelp(): ?string
216
    {
217
        return $this->help;
218
    }
219
220
    /**
221
     * @param string|null $help
222
     */
223
    public function setHelp(?string $help): void
224
    {
225
        $this->help = $help;
226
    }
227
228
    /**
229
     * @return string
230
     * @deprecated
231
     */
232
    public function getLogName(): string
233
    {
234
        return $this->logname;
0 ignored issues
show
Deprecated Code introduced by
The property Waca\DataObjects\RequestQueue::$logname has been deprecated: Removal due as part of #607 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

234
        return /** @scrutinizer ignore-deprecated */ $this->logname;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
235
    }
236
237
    /**
238
     * @param string $logName
239
     *
240
     * @deprecated
241
     */
242
    public function setLogName(string $logName): void
243
    {
244
        $this->logname = $logName;
0 ignored issues
show
Deprecated Code introduced by
The property Waca\DataObjects\RequestQueue::$logname has been deprecated: Removal due as part of #607 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

244
        /** @scrutinizer ignore-deprecated */ $this->logname = $logName;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
245
    }
246
247
    /**
248
     * @return string
249
     * @deprecated
250
     */
251
    public function getLegacyStatus(): string
252
    {
253
        return $this->legacystatus;
0 ignored issues
show
Deprecated Code introduced by
The property Waca\DataObjects\RequestQueue::$legacystatus has been deprecated: Removal due as part of #602 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

253
        return /** @scrutinizer ignore-deprecated */ $this->legacystatus;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
254
    }
255
256
    /**
257
     * @param string $legacyStatus
258
     *
259
     * @deprecated
260
     */
261
    public function setLegacyStatus(string $legacyStatus): void
262
    {
263
        $this->legacystatus = $legacyStatus;
0 ignored issues
show
Deprecated Code introduced by
The property Waca\DataObjects\RequestQueue::$legacystatus has been deprecated: Removal due as part of #602 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

263
        /** @scrutinizer ignore-deprecated */ $this->legacystatus = $legacyStatus;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
264
    }
265
}