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

LogSearchHelper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 100
ccs 0
cts 39
cp 0
rs 10
c 1
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 6 1
A fetch() 0 8 1
A byUser() 0 7 1
A byAction() 0 7 1
A byObjectType() 0 7 1
A byObjectId() 0 7 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\Helpers\SearchHelpers;
10
11
use Waca\DataObjects\Log;
12
use Waca\PdoDatabase;
13
14
class LogSearchHelper extends SearchHelperBase
15
{
16
	/**
17
	 * LogSearchHelper constructor.
18
	 *
19
	 * @param PdoDatabase $database
20
	 */
21
	protected function __construct(PdoDatabase $database)
22
	{
23
		parent::__construct($database, 'log', 'timestamp DESC');
24
	}
25
26
	/**
27
	 * Initiates a search for requests
28
	 *
29
	 * @param PdoDatabase $database
30
	 *
31
	 * @return LogSearchHelper
32
	 */
33
	public static function get(PdoDatabase $database)
34
	{
35
		$helper = new LogSearchHelper($database);
36
37
		return $helper;
38
	}
39
40
	/**
41
	 * Returns the requested requests
42
	 *
43
	 * @return Log[]
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...
44
	 */
45
	public function fetch()
46
	{
47
		$targetClass = Log::class;
48
49
		$returnedObjects = $this->fetchObjects($targetClass);
50
51
		return $returnedObjects;
52
	}
53
54
	/**
55
	 * Filters the results by user
56
	 *
57
	 * @param int $userId
58
	 *
59
	 * @return $this
60
	 */
61
	public function byUser($userId)
62
	{
63
		$this->whereClause .=' AND user = ?';
64
		$this->parameterList[] = $userId;
65
66
		return $this;
67
	}
68
69
	/**
70
	 * Filters the results by log action
71
	 *
72
	 * @param string $action
73
	 *
74
	 * @return $this
75
	 */
76
	public function byAction($action)
77
	{
78
		$this->whereClause .=' AND action = ?';
79
		$this->parameterList[] = $action;
80
81
		return $this;
82
	}
83
84
	/**
85
	 * Filters the results by object type
86
	 *
87
	 * @param string $objectType
88
	 *
89
	 * @return $this
90
	 */
91
	public function byObjectType($objectType)
92
	{
93
		$this->whereClause .=' AND objecttype = ?';
94
		$this->parameterList[] = $objectType;
95
96
		return $this;
97
	}
98
99
	/**
100
	 * Filters the results by object type
101
	 *
102
	 * @param integer $objectId
103
	 *
104
	 * @return $this
105
	 */
106
	public function byObjectId($objectId)
107
	{
108
		$this->whereClause .=' AND objectid = ?';
109
		$this->parameterList[] = $objectId;
110
111
		return $this;
112
	}
113
}