Completed
Branch newinternal (ffe884)
by Simon
04:07
created

RequestSearchHelper::excludingPurgedData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
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');
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
	 * Returns the requested requests
43
	 *
44
	 * @return Request[]
0 ignored issues
show
Documentation introduced by
Should the return type not be \Waca\DataObject[]?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
45
	 */
46
	public function fetch()
47
	{
48
		$targetClass = Request::class;
49
		$returnedObjects = $this->fetchObjects($targetClass);
50
		return $returnedObjects;
51
	}
52
53
	/**
54
	 * Filters the results by IP address
55
	 *
56
	 * @param string $ipAddress
57
	 *
58
	 * @return $this
59
	 */
60
	public function byIp($ipAddress)
61
	{
62
		$this->whereClause .=' AND (ip LIKE ? OR forwardedip LIKE ?)';
63
		$this->parameterList[] = $ipAddress;
64
		$this->parameterList[] = '%' . trim($ipAddress, '%') . '%';
65
66
		return $this;
67
	}
68
69
	/**
70
	 * Filters the results by email address
71
	 *
72
	 * @param string $emailAddress
73
	 *
74
	 * @return $this
75
	 */
76
	public function byEmailAddress($emailAddress)
77
	{
78
		$this->whereClause .=' AND email LIKE ?';
79
		$this->parameterList[] = $emailAddress;
80
81
		return $this;
82
	}
83
84
	/**
85
	 * Filters the results by name
86
	 *
87
	 * @param string $name
88
	 *
89
	 * @return $this
90
	 */
91
	public function byName($name)
92
	{
93
		$this->whereClause .=' AND name LIKE ?';
94
		$this->parameterList[] = $name;
95
96
		return $this;
97
	}
98
99
	/**
100
	 * Excludes a request from the results
101
	 *
102
	 * @param int $requestId
103
	 *
104
	 * @return $this
105
	 */
106
	public function excludingRequest($requestId)
107
	{
108
		$this->whereClause .=' AND id <> ?';
109
		$this->parameterList[] = $requestId;
110
111
		return $this;
112
	}
113
114
	/**
115
	 * Filters the results to only those with a confirmed email address
116
	 *
117
	 * @return $this
118
	 */
119
	public function withConfirmedEmail()
120
	{
121
		$this->whereClause .=' AND emailconfirm = ?';
122
		$this->parameterList[] = 'Confirmed';
123
124
		return $this;
125
	}
126
127
	/**
128
	 * Filters the results to exclude purged data
129
	 *
130
	 * @param SiteConfiguration $configuration
131
	 *
132
	 * @return $this
133
	 */
134
	public function excludingPurgedData(SiteConfiguration $configuration)
135
	{
136
		$this->whereClause .=' AND ip <> ? AND email <> ?';
137
		$this->parameterList[] = $configuration->getDataClearIp();
138
		$this->parameterList[] = $configuration->getDataClearEmail();
139
140
		return $this;
141
	}
142
}