Completed
Push — master ( 01705b...10ec3f )
by Morris
15:02 queued 02:44
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
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Morris Jobke <[email protected]>
6
 * @author Robin Appelman <[email protected]>
7
 * @author Thomas Müller <[email protected]>
8
 * @author Piotr Mrowczynski <[email protected]>
9
 *
10
 * @license AGPL-3.0
11
 *
12
 * This code is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License, version 3,
14
 * as published by the Free Software Foundation.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License, version 3,
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
23
 *
24
 */
25
26
namespace OC\Diagnostics;
27
28
use OCP\Diagnostics\IEventLogger;
29
30
class EventLogger implements IEventLogger {
31
	/**
32
	 * @var \OC\Diagnostics\Event[]
33
	 */
34
	private $events = [];
35
	
36
	/**
37
	 * @var bool - Module needs to be activated by some app
38
	 */
39
	private $activated = false;
40
41
	/**
42
	 * @inheritdoc
43
	 */
44
	public function start($id, $description) {
45
		if ($this->activated){
46
			$this->events[$id] = new Event($id, $description, microtime(true));
47
		}
48
	}
49
50
	/**
51
	 * @inheritdoc
52
	 */
53
	public function end($id) {
54
		if ($this->activated && isset($this->events[$id])) {
55
			$timing = $this->events[$id];
56
			$timing->end(microtime(true));
57
		}
58
	}
59
60
	/**
61
	 * @inheritdoc
62
	 */
63
	public function log($id, $description, $start, $end) {
64
		if ($this->activated) {
65
			$this->events[$id] = new Event($id, $description, $start);
66
			$this->events[$id]->end($end);
67
		}
68
	}
69
70
	/**
71
	 * @inheritdoc
72
	 */
73
	public function getEvents() {
74
		return $this->events;
75
	}
76
	
77
	/**
78
	 * @inheritdoc
79
	 */
80
	public function activate() {
81
		$this->activated = true;
82
	}
83
}
84