Completed
Push — master ( 612476...c205d6 )
by smiley
04:22
created

DBResultRow   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 18.52 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 13 4
A __get() 0 8 2
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
 */
18
class DBResultRow extends DBResult{
19
20
	/**
21
	 * @param string $name
22
	 * @param array  $arguments
23
	 *
24
	 * @return mixed|null
25
	 */
26
	public function __call(string $name, array $arguments){
27
28
		if(isset($this->array[$name])){
29
30
			if(isset($arguments[0]) && is_callable($arguments[0])){
31
				return call_user_func_array($arguments[0], [$this->array[$name]]);
32
			}
33
34
			return $this->array[$name];
35
		}
36
37
		return null;
38
	}
39
40
	/**
41
	 * @param string $name
42
	 *
43
	 * @return mixed|null
44
	 */
45
	public function __get(string $name) {
46
47
		if(isset($this->array[$name])){
48
			return $this->array[$name];
49
		}
50
51
		return null;
52
	}
53
54
	/**
55
	 * @param int   $offset
56
	 * @param array $value
57
	 *
58
	 * @return void
59
	 */
60 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...
61
62
		if(is_null($offset)){
63
			$this->array[] = $value; // @codeCoverageIgnore
64
		}
65
		else{
66
			$this->array[$offset] = $value;
67
		}
68
69
	}
70
71
}
72