Completed
Push — master ( 01705b...10ec3f )
by Morris
15:02 queued 02:44
created

Query   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A end() 0 3 1
A getParams() 0 3 1
A getSql() 0 3 1
A __construct() 0 6 1
A getStart() 0 3 1
A getDuration() 0 3 1
A getStartTime() 0 3 1
A getStacktrace() 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
 *
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
24
namespace OC\Diagnostics;
25
26
use OCP\Diagnostics\IQuery;
27
28
class Query implements IQuery {
29
	private $sql;
30
31
	private $params;
32
33
	private $start;
34
35
	private $end;
36
37
	private $stack;
38
39
	/**
40
	 * @param string $sql
41
	 * @param array $params
42
	 * @param int $start
43
	 */
44
	public function __construct($sql, $params, $start, array $stack) {
45
		$this->sql = $sql;
46
		$this->params = $params;
47
		$this->start = $start;
48
		$this->stack = $stack;
49
	}
50
51
	public function end($time) {
52
		$this->end = $time;
53
	}
54
55
	/**
56
	 * @return array
57
	 */
58
	public function getParams() {
59
		return $this->params;
60
	}
61
62
	/**
63
	 * @return string
64
	 */
65
	public function getSql() {
66
		return $this->sql;
67
	}
68
69
	/**
70
	 * @return float
71
	 */
72
	public function getStart() {
73
		return $this->start;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->start; (integer) is incompatible with the return type declared by the interface OCP\Diagnostics\IQuery::getStart of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
74
	}
75
	
76
	/**
77
	 * @return float
78
	 */
79
	public function getDuration() {
80
		return $this->end - $this->start;
81
	}
82
83
	public function getStartTime() {
84
		return $this->start;
85
	}
86
87
	public function getStacktrace() {
88
		return $this->stack;
89
	}
90
}
91