Completed
Push — master ( 718d85...a50954 )
by Piotr
43:28
created

QueryLogger::activate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Morris Jobke <[email protected]>
4
 * @author Robin Appelman <[email protected]>
5
 * @author Thomas Müller <[email protected]>
6
 * @author Piotr Mrowczynski <[email protected]>
7
 *
8
 * @copyright Copyright (c) 2017, ownCloud GmbH
9
 * @license AGPL-3.0
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License, version 3,
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
25
namespace OC\Diagnostics;
26
27
use OCP\Diagnostics\IQueryLogger;
28
29
class QueryLogger implements IQueryLogger {
30
	/**
31
	 * @var \OC\Diagnostics\Query
32
	 */
33
	protected $activeQuery;
34
35
	/**
36
	 * @var \OC\Diagnostics\Query[]
37
	 */
38
	protected $queries = [];
39
40
	/**
41
	 * @var bool - Module needs to be activated by some app
42
	 */
43
	private $activated = false;
44
45
	/**
46
	 * @inheritdoc
47
	 */
48
	public function startQuery($sql, array $params = null, array $types = null) {
49
		if ($this->activated) {
50
			$this->activeQuery = new Query($sql, $params, microtime(true));
0 ignored issues
show
Bug introduced by
It seems like $params defined by parameter $params on line 48 can also be of type null; however, OC\Diagnostics\Query::__construct() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
51
		}
52
	}
53
54
	/**
55
	 * @inheritdoc
56
	 */
57
	public function stopQuery() {
58
		if ($this->activated && $this->activeQuery) {
59
			$this->activeQuery->end(microtime(true));
60
			$this->queries[] = $this->activeQuery;
61
			$this->activeQuery = null;
62
		}
63
	}
64
65
	/**
66
	 * @inheritdoc
67
	 */
68
	public function getQueries() {
69
		return $this->queries;
70
	}
71
72
	/**
73
	 * @inheritdoc
74
	 */
75
	public function activate() {
76
		$this->activated = true;
77
	}
78
}
79