Passed
Pull Request — master (#297)
by Aimeos
10:30
created

DB::close()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2022
6
 * @package MShop
7
 * @subpackage Common
8
 */
9
10
11
namespace Aimeos\MShop\Common\Iterator;
12
13
14
/**
15
 * Default implementation for manager iterators
16
 *
17
 * @package MShop
18
 * @subpackage Common
19
 */
20
class DB implements Iface
21
{
22
	private $conn;
23
	private $current;
24
	private $result;
25
26
27
	/**
28
	 * Initializes the object
29
	 *
30
	 * @param \Aimeos\Base\DB\Connection\Iface $conn Database connection
31
	 * @param \Aimeos\Base\DB\Result\Iface $result Result set to iterate over
32
	 */
33
	public function __construct( \Aimeos\Base\DB\Connection\Iface $conn, \Aimeos\Base\DB\Result\Iface $result )
34
	{
35
		$this->current = $result->fetch();
36
		$this->result = $result;
37
		$this->conn = $conn;
38
	}
39
40
41
	/**
42
	 * Terminates the iterator
43
	 */
44
	public function close() : void
45
	{
46
		$this->current = null;
47
		$this->result->finish();
48
		$this->conn->close();
49
	}
50
51
52
	/**
53
	 * Returns the current element
54
	 *
55
	 * @return array Associative list of key/value pairs of the current record
56
	 */
57
	#[\ReturnTypeWillChange]
58
	public function current()
59
	{
60
		return $this->current;
61
	}
62
63
64
	/**
65
	 * Returns the key of the current element
66
	 *
67
	 * @return string ID of the current record
68
	 */
69
	#[\ReturnTypeWillChange]
70
	public function key()
71
	{
72
		return is_array( $this->current ) ? current( $this->current ) : null;
73
	}
74
75
76
	/**
77
	 * Moves forward to next element
78
	 */
79
	public function next() : void
80
	{
81
		$this->current = $this->result->fetch();
82
	}
83
84
85
	/**
86
	 * Rewinds the Iterator to the first element
87
	 */
88
	public function rewind() : void
89
	{
90
	}
91
92
93
	/**
94
	 * Checks if current position is valid
95
	 *
96
	 * @return bool TRUE if more records are available, FALSE if not
97
	 */
98
	public function valid() : bool
99
	{
100
		return is_array( $this->current );
101
	}
102
}
103