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

EventLogger   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A start() 0 5 2
A end() 0 6 3
A log() 0 6 2
A getEvents() 0 3 1
A activate() 0 3 1
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\IEventLogger;
28
29
class EventLogger implements IEventLogger {
30
	/**
31
	 * @var \OC\Diagnostics\Event[]
32
	 */
33
	private $events = [];
34
	
35
	/**
36
	 * @var bool - Module needs to be activated by some app
37
	 */
38
	private $activated = false;
39
40
	/**
41
	 * @inheritdoc
42
	 */
43
	public function start($id, $description) {
44
		if ($this->activated){
45
			$this->events[$id] = new Event($id, $description, microtime(true));
46
		}
47
	}
48
49
	/**
50
	 * @inheritdoc
51
	 */
52
	public function end($id) {
53
		if ($this->activated && isset($this->events[$id])) {
54
			$timing = $this->events[$id];
55
			$timing->end(microtime(true));
56
		}
57
	}
58
59
	/**
60
	 * @inheritdoc
61
	 */
62
	public function log($id, $description, $start, $end) {
63
		if ($this->activated) {
64
			$this->events[$id] = new Event($id, $description, $start);
65
			$this->events[$id]->end($end);
66
		}
67
	}
68
69
	/**
70
	 * @inheritdoc
71
	 */
72
	public function getEvents() {
73
		return $this->events;
74
	}
75
	
76
	/**
77
	 * @inheritdoc
78
	 */
79
	public function activate() {
80
		$this->activated = true;
81
	}
82
}
83