Completed
Pull Request — newinternal (#285)
by Simon
06:16 queued 03:05
created

RequestSearchHelper::excludingRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 4
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\SiteConfiguration;
14
15
class RequestSearchHelper extends SearchHelperBase
16
{
17
    /**
18
     * RequestSearchHelper constructor.
19
     *
20
     * @param PdoDatabase $database
21
     */
22
    protected function __construct(PdoDatabase $database)
23
    {
24
        parent::__construct($database, 'request', Request::class);
25
    }
26
27
    /**
28
     * Initiates a search for requests
29
     *
30
     * @param PdoDatabase $database
31
     *
32
     * @return RequestSearchHelper
33
     */
34
    public static function get(PdoDatabase $database)
35
    {
36
        $helper = new RequestSearchHelper($database);
37
38
        return $helper;
39
    }
40
41
    /**
42
     * Filters the results by IP address
43
     *
44
     * @param string $ipAddress
45
     *
46
     * @return $this
47
     */
48
    public function byIp($ipAddress)
49
    {
50
        $this->whereClause .= ' AND (ip LIKE ? OR forwardedip LIKE ?)';
51
        $this->parameterList[] = $ipAddress;
52
        $this->parameterList[] = '%' . trim($ipAddress, '%') . '%';
53
54
        return $this;
55
    }
56
57
    /**
58
     * Filters the results by email address
59
     *
60
     * @param string $emailAddress
61
     *
62
     * @return $this
63
     */
64
    public function byEmailAddress($emailAddress)
65
    {
66
        $this->whereClause .= ' AND email LIKE ?';
67
        $this->parameterList[] = $emailAddress;
68
69
        return $this;
70
    }
71
72
    /**
73
     * Filters the results by name
74
     *
75
     * @param string $name
76
     *
77
     * @return $this
78
     */
79
    public function byName($name)
80
    {
81
        $this->whereClause .= ' AND name LIKE ?';
82
        $this->parameterList[] = $name;
83
84
        return $this;
85
    }
86
87
    /**
88
     * Excludes a request from the results
89
     *
90
     * @param int $requestId
91
     *
92
     * @return $this
93
     */
94
    public function excludingRequest($requestId)
95
    {
96
        $this->whereClause .= ' AND id <> ?';
97
        $this->parameterList[] = $requestId;
98
99
        return $this;
100
    }
101
102
    /**
103
     * Filters the results to only those with a confirmed email address
104
     *
105
     * @return $this
106
     */
107
    public function withConfirmedEmail()
108
    {
109
        $this->whereClause .= ' AND emailconfirm = ?';
110
        $this->parameterList[] = 'Confirmed';
111
112
        return $this;
113
    }
114
115
    /**
116
     * Filters the results to exclude purged data
117
     *
118
     * @param SiteConfiguration $configuration
119
     *
120
     * @return $this
121
     */
122
    public function excludingPurgedData(SiteConfiguration $configuration)
123
    {
124
        $this->whereClause .= ' AND ip <> ? AND email <> ?';
125
        $this->parameterList[] = $configuration->getDataClearIp();
126
        $this->parameterList[] = $configuration->getDataClearEmail();
127
128
        return $this;
129
    }
130
}