Completed
Push — search ( af3757...7ef0dc )
by Simon
03:28 queued 03:24
created

RequestSearchHelper::byCommentSecurity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
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\Helpers\SearchHelpers;
10
11
use Waca\DataObjects\Request;
12
use Waca\PdoDatabase;
13
use Waca\RequestStatus;
14
use Waca\SiteConfiguration;
0 ignored issues
show
Bug introduced by
The type Waca\SiteConfiguration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
class RequestSearchHelper extends SearchHelperBase
17
{
18
    /**
19
     * RequestSearchHelper constructor.
20
     *
21
     * @param PdoDatabase $database
22
     */
23
    protected function __construct(PdoDatabase $database)
24
    {
25
        parent::__construct($database, 'request', Request::class);
26
    }
27
28
    /**
29
     * Initiates a search for requests
30
     *
31
     * @param PdoDatabase $database
32
     *
33
     * @return RequestSearchHelper
34
     */
35
    public static function get(PdoDatabase $database)
36
    {
37
        $helper = new RequestSearchHelper($database);
38
39
        return $helper;
40
    }
41
42
    /**
43
     * Filters the results by IP address
44
     *
45
     * @param string $ipAddress
46
     *
47
     * @return $this
48
     */
49
    public function byIp($ipAddress)
50
    {
51
        $this->whereClause .= ' AND (ip LIKE ? OR forwardedip LIKE ?)';
52
        $this->parameterList[] = $ipAddress;
53
        $this->parameterList[] = '%' . trim($ipAddress, '%') . '%';
54
55
        return $this;
56
    }
57
58
    /**
59
     * Filters the results by email address
60
     *
61
     * @param string $emailAddress
62
     *
63
     * @return $this
64
     */
65
    public function byEmailAddress($emailAddress)
66
    {
67
        $this->whereClause .= ' AND email LIKE ?';
68
        $this->parameterList[] = $emailAddress;
69
70
        return $this;
71
    }
72
73
    /**
74
     * Filters the results by name
75
     *
76
     * @param string $name
77
     *
78
     * @return $this
79
     */
80
    public function byName($name)
81
    {
82
        $this->whereClause .= ' AND name LIKE ?';
83
        $this->parameterList[] = $name;
84
85
        return $this;
86
    }
87
88
    /**
89
     * Filters the results by comment
90
     *
91
     * @param string $comment
92
     *
93
     * @return $this
94
     */
95
    public function byComment($comment)
96
    {
97
        $this->modifiersClause = 'DISTINCT';
98
        $this->joinClause .= ' INNER JOIN comment c ON origin.id = c.request';
99
        $this->whereClause .= ' AND c.comment LIKE ?';
100
        $this->parameterList[] = $comment;
101
102
        return $this;
103
    }
104
105
    /**
106
     * Filters the results by comment security
107
     *
108
     * @param array $security List of allowed values for the security clause
109
     *
110
     * @return $this
111
     */
112
    public function byCommentSecurity(array $security)
113
    {
114
        $this->inClause('c.visibility', $security);
115
116
        return $this;
117
    }
118
119
    /**
120
     * Filters the requests to those with a defined status
121
     *
122
     * @param $status
123
     *
124
     * @return $this
125
     */
126
    public function byStatus($status)
127
    {
128
        $this->whereClause .= ' AND status = ?';
129
        $this->parameterList[] = $status;
130
131
        return $this;
132
    }
133
134
    /**
135
     * Excludes a request from the results
136
     *
137
     * @param int $requestId
138
     *
139
     * @return $this
140
     */
141
    public function excludingRequest($requestId)
142
    {
143
        $this->whereClause .= ' AND id <> ?';
144
        $this->parameterList[] = $requestId;
145
146
        return $this;
147
    }
148
149
    /**
150
     * Filters the results to only those with a confirmed email address
151
     *
152
     * @return $this
153
     */
154
    public function withConfirmedEmail()
155
    {
156
        $this->whereClause .= ' AND emailconfirm = ?';
157
        $this->parameterList[] = 'Confirmed';
158
159
        return $this;
160
    }
161
162
    /**
163
     * Filters the results to exclude purged data
164
     *
165
     * @param SiteConfiguration $configuration
166
     *
167
     * @return $this
168
     */
169
    public function excludingPurgedData(SiteConfiguration $configuration)
170
    {
171
        $this->whereClause .= ' AND ip <> ? AND email <> ?';
172
        $this->parameterList[] = $configuration->getDataClearIp();
173
        $this->parameterList[] = $configuration->getDataClearEmail();
174
175
        return $this;
176
    }
177
178
    /**
179
     * Filters the requests to those without a defined status
180
     *
181
     * @param $status
182
     *
183
     * @return $this
184
     */
185
    public function excludingStatus($status)
186
    {
187
        $this->whereClause .= ' AND status <> ?';
188
        $this->parameterList[] = $status;
189
190
        return $this;
191
    }
192
193
    /**
194
     * Filters the requests to those which have failed an auto-creation
195
     *
196
     * @return $this
197
     */
198
    public function isHospitalised()
199
    {
200
        $this->whereClause .= ' AND status = ?';
201
        $this->parameterList[] =  RequestStatus::HOSPITAL;
202
203
        return $this;
204
    }
205
206
    /**
207
     * Filters the requests to those which have not failed an auto-creation
208
     *
209
     * @return $this
210
     */
211
    public function notHospitalised()
212
    {
213
        $this->whereClause .= ' AND status <> ?';
214
        $this->parameterList[] =  RequestStatus::HOSPITAL;
215
216
        return $this;
217
    }
218
219
    public function fetchByStatus($statuses)
220
    {
221
        return $this->fetchByParameter(' AND status = ?', $statuses);
222
    }
223
}
224