Completed
Push — master ( 319aa4...523298 )
by smiley
04:24
created

DBResultRow   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 65
Duplicated Lines 15.38 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 13 4
A __get() 0 8 2
A pluck() 0 3 1
A offsetSet() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Class DBResultRow
4
 *
5
 * @filesource   DBResultRow.php
6
 * @created      23.05.2017
7
 * @package      chillerlan\Database
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2017 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Database;
14
15
/**
16
 *
17
 * __call() -> fieldname($func)
18
 */
19
class DBResultRow extends DBResult{
20
21
	/**
22
	 * @param string $name
23
	 * @param array  $arguments
24
	 *
25
	 * @return mixed|null
26
	 */
27
	public function __call(string $name, array $arguments){
28
29
		if(isset($this->array[$name])){
30
31
			if(isset($arguments[0]) && is_callable($arguments[0])){
32
				return call_user_func_array($arguments[0], [$this->array[$name]]);
33
			}
34
35
			return $this->array[$name];
36
		}
37
38
		return null;
39
	}
40
41
	/**
42
	 * @param string $name
43
	 *
44
	 * @return mixed|null
45
	 */
46
	public function __get(string $name) {
47
48
		if(isset($this->array[$name])){
49
			return $this->array[$name];
50
		}
51
52
		return null;
53
	}
54
55
	/**
56
	 * @link http://api.prototypejs.org/language/Enumerable/prototype/pluck/
57
	 *
58
	 * @param string $property
59
	 *
60
	 * @return array
61
	 */
62
	public function pluck(string $property):array {
63
		return [];
64
	}
65
66
	/**
67
	 * @param int   $offset
68
	 * @param array $value
69
	 *
70
	 * @return void
71
	 */
72 View Code Duplication
	public function offsetSet($offset, $value){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
74
		if(is_null($offset)){
75
			$this->array[] = $value;
76
		}
77
		else{
78
			$this->array[$offset] = $value;
79
		}
80
81
	}
82
83
}
84