Passed
Push — master ( 78ff77...606203 )
by Aimeos
04:53
created

DBAL::fetch()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 13
rs 9.6111
c 0
b 0
f 0
cc 5
nc 4
nop 1
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021-2022
6
 * @package MW
7
 * @subpackage DB
8
 */
9
10
11
namespace Aimeos\Base\DB\Result;
12
13
14
/**
15
 * Database result set object for DBAL connections.
16
 *
17
 * @package MW
18
 * @subpackage DB
19
 */
20
class DBAL extends \Aimeos\Base\DB\Result\Base implements \Aimeos\Base\DB\Result\Iface
21
{
22
	private $result;
23
24
25
	/**
26
	 * Initializes the result object.
27
	 *
28
	 * @param \Doctrine\DBAL\Driver\Statement|\Doctrine\DBAL\Driver\Result $result Result object created by DBAL
29
	 */
30
	public function __construct( $result )
31
	{
32
		$this->result = $result;
33
	}
34
35
36
	/**
37
	 * Clears the result set if anything is left.
38
	 */
39
	public function __destruct()
40
	{
41
		$this->result->free();
0 ignored issues
show
Bug introduced by
The method free() does not exist on Doctrine\DBAL\Driver\Statement. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
		$this->result->/** @scrutinizer ignore-call */ 
42
                 free();

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...
42
	}
43
44
45
	/**
46
	 * Returns the number of rows affected by a INSERT, UPDATE or DELETE statement.
47
	 *
48
	 * @return int Number of touched records
49
	 * @throws \Aimeos\Base\DB\Exception if an error occured in the unterlying driver
50
	 */
51
	public function affectedRows() : int
52
	{
53
		try {
54
			return $this->result->rowCount();
0 ignored issues
show
Bug introduced by
The method rowCount() does not exist on Doctrine\DBAL\Driver\Statement. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
			return $this->result->/** @scrutinizer ignore-call */ rowCount();

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...
55
		} catch( \Doctrine\DBAL\Driver\Exception $e ) {
56
			throw new \Aimeos\Base\DB\Exception( $e->getMessage(), $e->getCode() );
57
		}
58
	}
59
60
61
	/**
62
	 * Retrieves the next row from database result set.
63
	 *
64
	 * @param int $style The data can be returned as associative or numerical array
65
	 * @return array|null Numeric or associative array of columns returned by the database or null if no more rows are available
66
	 * @throws \Aimeos\Base\DB\Exception if an error occured in the unterlying driver or the fetch style is unknown
67
	 */
68
	public function fetch( int $style = \Aimeos\Base\DB\Result\Base::FETCH_ASSOC ) : ?array
69
	{
70
		try
71
		{
72
			if( $style === \Aimeos\Base\DB\Result\Base::FETCH_NUM ) {
73
				return $this->result->fetchNumeric() ?: null;
0 ignored issues
show
Bug introduced by
The method fetchNumeric() does not exist on Doctrine\DBAL\Driver\Statement. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
				return $this->result->/** @scrutinizer ignore-call */ fetchNumeric() ?: null;

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...
74
			} else {
75
				return $this->result->fetchAssociative() ?: null;
0 ignored issues
show
Bug introduced by
The method fetchAssociative() does not exist on Doctrine\DBAL\Driver\Statement. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

75
				return $this->result->/** @scrutinizer ignore-call */ fetchAssociative() ?: null;

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...
76
			}
77
		}
78
		catch( \Doctrine\DBAL\Driver\Exception $e )
79
		{
80
			throw new \Aimeos\Base\DB\Exception( $e->getMessage(), $e->getCode() );
81
		}
82
	}
83
84
85
	/**
86
	 * Cleans up pending database result sets.
87
	 *
88
	 * @return \Aimeos\Base\DB\Result\Iface Result instance for method chaining
89
	 * @throws \Aimeos\Base\DB\Exception if an error occured in the unterlying driver
90
	 */
91
	public function finish() : Iface
92
	{
93
		try {
94
			$this->result->free();
95
		} catch( \Doctrine\DBAL\Driver\Exception $e ) {
96
			throw new \Aimeos\Base\DB\Exception( $e->getMessage(), $e->getCode() );
97
		}
98
99
		return $this;
100
	}
101
102
103
	/**
104
	 * Retrieves the next database result set.
105
	 *
106
	 * @return bool True if another result is available, false if not
107
	 */
108
	public function nextResult() : bool
109
	{
110
		return false;
111
	}
112
}
113