Passed
Push — search ( bdb480...5e7f6e )
by Simon
17:14 queued 07:17
created

RequestForm::setDomain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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 RequestForm extends DataObject
16
{
17
    /** @var int */
18
    private $enabled = 0;
19
    /** @var int */
20
    private $domain;
21
    /** @var string */
22
    private $name;
23
    /** @var string */
24
    private $publicendpoint;
25
    /** @var string */
26
    private $formcontent;
27
    /** @var int|null */
28
    private $overridequeue;
29
30
    public function save()
31
    {
32
        if ($this->isNew()) {
33
            // insert
34
            $statement = $this->dbObject->prepare(<<<SQL
35
                INSERT INTO requestform (
36
                    enabled, domain, name, publicendpoint, formcontent, overridequeue
37
                ) VALUES (
38
                    :enabled, :domain, :name, :publicendpoint, :formcontent, :overridequeue
39
                );
40
SQL
41
            );
42
43
            $statement->bindValue(":enabled", $this->enabled);
44
            $statement->bindValue(":domain", $this->domain);
45
            $statement->bindValue(":name", $this->name);
46
            $statement->bindValue(":publicendpoint", $this->publicendpoint);
47
            $statement->bindValue(":formcontent", $this->formcontent);
48
            $statement->bindValue(":overridequeue", $this->overridequeue);
49
50
            if ($statement->execute()) {
51
                $this->id = (int)$this->dbObject->lastInsertId();
52
            }
53
            else {
54
                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

54
                throw new Exception(/** @scrutinizer ignore-type */ $statement->errorInfo());
Loading history...
55
            }
56
        }
57
        else {
58
            $statement = $this->dbObject->prepare(<<<SQL
59
                UPDATE requestform SET
60
                    enabled = :enabled,
61
                    domain = :domain,
62
                    name = :name,
63
                    publicendpoint = :publicendpoint,
64
                    formcontent = :formcontent,
65
                    overridequeue = :overridequeue,
66
                
67
                    updateversion = updateversion + 1
68
				WHERE id = :id AND updateversion = :updateversion;
69
SQL
70
            );
71
72
            $statement->bindValue(":enabled", $this->enabled);
73
            $statement->bindValue(":domain", $this->domain);
74
            $statement->bindValue(":name", $this->name);
75
            $statement->bindValue(":publicendpoint", $this->publicendpoint);
76
            $statement->bindValue(":formcontent", $this->formcontent);
77
            $statement->bindValue(":overridequeue", $this->overridequeue);
78
79
            $statement->bindValue(':id', $this->id);
80
            $statement->bindValue(':updateversion', $this->updateversion);
81
82
            if (!$statement->execute()) {
83
                throw new Exception($statement->errorInfo());
84
            }
85
86
            if ($statement->rowCount() !== 1) {
87
                throw new OptimisticLockFailedException();
88
            }
89
90
            $this->updateversion++;
91
        }
92
    }
93
94
    /**
95
     * @return bool
96
     */
97
    public function isEnabled(): bool
98
    {
99
        return $this->enabled == 1;
100
    }
101
102
    /**
103
     * @param bool $enabled
104
     */
105
    public function setEnabled(bool $enabled): void
106
    {
107
        $this->enabled = $enabled ? 1 : 0;
108
    }
109
110
    /**
111
     * @return int
112
     */
113
    public function getDomain(): int
114
    {
115
        return $this->domain;
116
    }
117
118
    /**
119
     * @param int $domain
120
     */
121
    public function setDomain(int $domain): void
122
    {
123
        $this->domain = $domain;
124
    }
125
126
    /**
127
     * @return string
128
     */
129
    public function getName(): string
130
    {
131
        return $this->name;
132
    }
133
134
    /**
135
     * @param string $name
136
     */
137
    public function setName(string $name): void
138
    {
139
        $this->name = $name;
140
    }
141
142
    /**
143
     * @return string
144
     */
145
    public function getPublicEndpoint(): string
146
    {
147
        return $this->publicendpoint;
148
    }
149
150
    /**
151
     * @param string $publicEndpoint
152
     */
153
    public function setPublicEndpoint(string $publicEndpoint): void
154
    {
155
        $this->publicendpoint = $publicEndpoint;
156
    }
157
158
    /**
159
     * @return string
160
     */
161
    public function getFormContent(): string
162
    {
163
        return $this->formcontent;
164
    }
165
166
    /**
167
     * @param string $formContent
168
     */
169
    public function setFormContent(string $formContent): void
170
    {
171
        $this->formcontent = $formContent;
172
    }
173
174
    /**
175
     * @return int|null
176
     */
177
    public function getOverrideQueue(): ?int
178
    {
179
        return $this->overridequeue;
180
    }
181
182
    /**
183
     * @param int|null $overrideQueue
184
     */
185
    public function setOverrideQueue(?int $overrideQueue): void
186
    {
187
        $this->overridequeue = $overrideQueue;
188
    }
189
190
191
}