Passed
Push — master ( 18bafe...2ff0c9 )
by Julius
14:52 queued 13s
created

Event::end()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
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);
0 ignored issues
show
Documentation Bug introduced by
It seems like microtime(true) can also be of type string. However, the property $end is declared as type double. Maybe add an additional type check?

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 $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. 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.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
100
		}
101
		return $this->end - $this->start;
102
	}
103
104
	public function __toString() {
105
		return $this->getId() . ' ' . $this->getDescription() . ' ' . $this->getDuration();
106
	}
107
}
108