Completed
Push — master ( 211db0...0244fa )
by Chris
03:02
created

Result::setInfo()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 13
loc 13
rs 9.4286
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
namespace Darya\Storage;
3
4
use Darya\Storage\Query;
5
6
/**
7
 * Darya's storage query result.
8
 * 
9
 * @author Chris Andrew <[email protected]>
10
 */
11
class Result {
12
	
13
	/**
14
	 * The storage query that produced this result.
15
	 * 
16
	 * @var Query
17
	 */
18
	protected $query;
19
	
20
	/**
21
	 * An associative array of the result data.
22
	 * 
23
	 * @var array
24
	 */
25
	protected $data;
26
	
27
	/**
28
	 * The error that occurred when executing the query, if any.
29
	 * 
30
	 * @var Error|null
31
	 */
32
	protected $error;
33
	
34
	/**
35
	 * The number of rows in the result data.
36
	 * 
37
	 * @var int
38
	 */
39
	protected $count;
40
	
41
	/**
42
	 * The set of fields available for each row in the result.
43
	 * 
44
	 * @var array
45
	 */
46
	protected $fields;
47
	
48
	/**
49
	 * Auto incremented primary key of an inserted row.
50
	 * 
51
	 * @var int
52
	 */
53
	protected $insertId;
54
	
55
	/**
56
	 * Error captured from the query that produced this result.
57
	 * 
58
	 * @var Error
59
	 */
60
	protected $error;
61
	
62
	/**
63
	 * Instantiate a new storage query result.
64
	 * 
65
	 * @param Query $query
66
	 * @param array $data  [optional]
67
	 * @param array $info  [optional]
68
	 * @param Error $error [optional]
69
	 */
70
	public function __construct(Query $query, array $data = array(), array $info = array(), Error $error = null) {
71
		$this->query = $query;
72
		$this->data = $data;
73
		$this->error = $error;
74
	}
75
	
76
	/**
77
	 * Set the result info.
78
	 * 
79
	 * Accepts the keys 'affected', 'count', 'insert_id' and 'fields'.
80
	 * 
81
	 * @param array $info
82
	 */
83 View Code Duplication
	protected function setInfo(array $info) {
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...
84
		$defaults = array(
85
			'count' => 0,
86
			'fields' => array(),
87
			'affected' => 0,
88
			'insert_id' => 0
89
		);
90
		
91
		foreach ($defaults as $key => $default) {
92
			$property = static::snakeToCamel($key);
0 ignored issues
show
Bug introduced by
The method snakeToCamel() does not seem to exist on object<Darya\Storage\Result>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
93
			$this->$property = isset($info[$key]) ? $info[$key] : $default;
94
		}
95
	}
96
	
97
}
98