|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Morris Jobke <[email protected]> |
|
6
|
|
|
* @author Robin Appelman <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @license AGPL-3.0 |
|
9
|
|
|
* |
|
10
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
12
|
|
|
* as published by the Free Software Foundation. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
namespace OC\Diagnostics; |
|
24
|
|
|
|
|
25
|
|
|
use OCP\Diagnostics\IEvent; |
|
26
|
|
|
|
|
27
|
|
|
class Event implements IEvent { |
|
28
|
|
|
/** |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $id; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var float |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $start; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var float |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $end; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $description; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param string $id |
|
50
|
|
|
* @param string $description |
|
51
|
|
|
* @param float $start |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct($id, $description, $start) { |
|
54
|
|
|
$this->id = $id; |
|
55
|
|
|
$this->description = $description; |
|
56
|
|
|
$this->start = $start; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param float $time |
|
61
|
|
|
*/ |
|
62
|
|
|
public function end($time) { |
|
63
|
|
|
$this->end = $time; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return float |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getStart() { |
|
70
|
|
|
return $this->start; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getId() { |
|
77
|
|
|
return $this->id; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getDescription() { |
|
84
|
|
|
return $this->description; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return float |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getEnd() { |
|
91
|
|
|
return $this->end; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return float |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getDuration() { |
|
98
|
|
|
if (!$this->end) { |
|
99
|
|
|
$this->end = microtime(true); |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
return $this->end - $this->start; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function __toString() { |
|
105
|
|
|
return $this->getId() . ' ' . $this->getDescription() . ' ' . $this->getDuration(); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.