Issues (50)

src/DB/Result/DBAL.php (6 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021-2025
6
 * @package Base
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 Base
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
		$class = '\Doctrine\DBAL\Driver\Result';
42
43
		if( $this->result instanceof $class ) {
44
			$this->result->free();
0 ignored issues
show
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

44
			$this->result->/** @scrutinizer ignore-call */ 
45
                  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...
45
		}
46
47
		$class = '\Doctrine\DBAL\Driver\Statement';
48
49
		if( $this->result instanceof $class ) {
50
			$this->result->closeCursor();
0 ignored issues
show
The method closeCursor() does not exist on Doctrine\DBAL\Driver\Result. ( Ignorable by Annotation )

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

50
			$this->result->/** @scrutinizer ignore-call */ 
51
                  closeCursor();

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...
The method closeCursor() 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

50
			$this->result->/** @scrutinizer ignore-call */ 
51
                  closeCursor();

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...
51
		}
52
	}
53
54
55
	/**
56
	 * Returns the number of rows affected by a INSERT, UPDATE or DELETE statement.
57
	 *
58
	 * @return int Number of touched records
59
	 * @throws \Aimeos\Base\DB\Exception if an error occured in the unterlying driver
60
	 */
61
	public function affectedRows() : int
62
	{
63
		try {
64
			return $this->result->rowCount();
0 ignored issues
show
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

64
			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...
65
		} catch( \PDOException $e ) {
66
			throw new \Aimeos\Base\DB\Exception( $e->getMessage(), $e->getCode() );
67
		}
68
	}
69
70
71
	/**
72
	 * Retrieves the next row from database result set.
73
	 *
74
	 * @param int $style The data can be returned as associative or numerical array
75
	 * @return array|null Numeric or associative array of columns returned by the database or null if no more rows are available
76
	 * @throws \Aimeos\Base\DB\Exception if an error occured in the unterlying driver or the fetch style is unknown
77
	 */
78
	public function fetch( int $style = \Aimeos\Base\DB\Result\Base::FETCH_ASSOC ) : ?array
79
	{
80
		try
81
		{
82
			$fetch = $style === \Aimeos\Base\DB\Result\Base::FETCH_NUM ? \PDO::FETCH_NUM : \PDO::FETCH_ASSOC;
83
			return $this->result->fetch( $fetch ) ?: null;
0 ignored issues
show
The method fetch() 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

83
			return $this->result->/** @scrutinizer ignore-call */ fetch( $fetch ) ?: 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...
The method fetch() does not exist on Doctrine\DBAL\Driver\Result. Did you maybe mean fetchOne()? ( Ignorable by Annotation )

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

83
			return $this->result->/** @scrutinizer ignore-call */ fetch( $fetch ) ?: 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...
84
		}
85
		catch( \PDOException $e )
86
		{
87
			throw new \Aimeos\Base\DB\Exception( $e->getMessage(), $e->getCode() );
88
		}
89
	}
90
91
92
	/**
93
	 * Cleans up pending database result sets.
94
	 *
95
	 * @return \Aimeos\Base\DB\Result\Iface Result instance for method chaining
96
	 * @throws \Aimeos\Base\DB\Exception if an error occured in the unterlying driver
97
	 */
98
	public function finish() : Iface
99
	{
100
		try
101
		{
102
			$class = '\Doctrine\DBAL\Driver\Result';
103
104
			if( $this->result instanceof $class ) {
105
				$this->result->free();
106
			}
107
108
			$class = '\Doctrine\DBAL\Driver\Statement';
109
110
			if( $this->result instanceof $class ) {
111
				$this->result->closeCursor();
112
			}
113
		}
114
		catch( \PDOException $e )
115
		{
116
			throw new \Aimeos\Base\DB\Exception( $e->getMessage(), $e->getCode() );
117
		}
118
119
		return $this;
120
	}
121
122
123
	/**
124
	 * Retrieves the next database result set.
125
	 *
126
	 * @return bool True if another result is available, false if not
127
	 */
128
	public function nextResult() : bool
129
	{
130
		return false;
131
	}
132
}
133