Skip to content

Commit 0490d9f

Browse files
committed
Fix phpstan issue with PreparedQuery classes' statement property
1 parent db2c0b3 commit 0490d9f

5 files changed

Lines changed: 6 additions & 39 deletions

File tree

phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ parameters:
3333
- '#Call to an undefined method CodeIgniter\\Database\\ConnectionInterface::(tableExists|protectIdentifiers|setAliasedTables|escapeIdentifiers|affectedRows|addTableAlias|getIndexData)\(\)#'
3434
- '#Call to an undefined method CodeIgniter\\HTTP\\Request::(getPath|getSegments|getMethod|setLocale|getPost)\(\)#'
3535
- '#Call to an undefined method CodeIgniter\\Router\\RouteCollectionInterface::(getDefaultNamespace|isFiltered|getFilterForRoute|getRoutesOptions)\(\)#'
36-
- '#Call to function is_null\(\) with mysqli_stmt\|resource will always evaluate to false#'
3736
- '#Cannot access property [\$a-z_]+ on ((bool\|)?object\|resource)#'
3837
- '#Cannot call method [a-zA-Z_]+\(\) on ((bool\|)?object\|resource)#'
3938
- '#Method CodeIgniter\\Database\\ConnectionInterface::query\(\) invoked with 3 parameters, 1-2 required#'

system/Database/MySQLi/PreparedQuery.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
*/
4949
class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface
5050
{
51-
5251
/**
5352
* Prepares the query against the database, and saves the connection
5453
* info necessary to execute the query later.
@@ -77,8 +76,6 @@ public function _prepare(string $sql, array $options = [])
7776
return $this;
7877
}
7978

80-
//--------------------------------------------------------------------
81-
8279
/**
8380
* Takes a new set of data and runs it against the currently
8481
* prepared query. Upon success, will return a Results object.
@@ -89,7 +86,7 @@ public function _prepare(string $sql, array $options = [])
8986
*/
9087
public function _execute(array $data): bool
9188
{
92-
if (is_null($this->statement))
89+
if (! isset($this->statement))
9390
{
9491
throw new BadMethodCallException('You must call prepare before trying to execute a prepared statement.');
9592
}
@@ -120,8 +117,6 @@ public function _execute(array $data): bool
120117
return $this->statement->execute();
121118
}
122119

123-
//--------------------------------------------------------------------
124-
125120
/**
126121
* Returns the result object for the prepared query.
127122
*
@@ -131,6 +126,4 @@ public function _getResult()
131126
{
132127
return $this->statement->get_result();
133128
}
134-
135-
//--------------------------------------------------------------------
136129
}

system/Database/Postgre/PreparedQuery.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
*/
5050
class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface
5151
{
52-
5352
/**
5453
* Stores the name this query can be
5554
* used under by postgres. Only used internally.
@@ -66,8 +65,6 @@ class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface
6665
*/
6766
protected $result;
6867

69-
//--------------------------------------------------------------------
70-
7168
/**
7269
* Prepares the query against the database, and saves the connection
7370
* info necessary to execute the query later.
@@ -101,8 +98,6 @@ public function _prepare(string $sql, array $options = [])
10198
return $this;
10299
}
103100

104-
//--------------------------------------------------------------------
105-
106101
/**
107102
* Takes a new set of data and runs it against the currently
108103
* prepared query. Upon success, will return a Results object.
@@ -113,7 +108,7 @@ public function _prepare(string $sql, array $options = [])
113108
*/
114109
public function _execute(array $data): bool
115110
{
116-
if (is_null($this->statement))
111+
if (! isset($this->statement))
117112
{
118113
throw new BadMethodCallException('You must call prepare before trying to execute a prepared statement.');
119114
}
@@ -123,8 +118,6 @@ public function _execute(array $data): bool
123118
return (bool) $this->result;
124119
}
125120

126-
//--------------------------------------------------------------------
127-
128121
/**
129122
* Returns the result object for the prepared query.
130123
*
@@ -135,8 +128,6 @@ public function _getResult()
135128
return $this->result;
136129
}
137130

138-
//--------------------------------------------------------------------
139-
140131
/**
141132
* Replaces the ? placeholders with $1, $2, etc parameters for use
142133
* within the prepared query.
@@ -155,6 +146,4 @@ public function parameterize(string $sql): string
155146
return "\${$count}";
156147
}, $sql);
157148
}
158-
159-
//--------------------------------------------------------------------
160149
}

system/Database/SQLite3/PreparedQuery.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,13 @@
4949

5050
class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface
5151
{
52-
5352
/**
5453
* The SQLite3Result resource, or false.
5554
*
5655
* @var Result|boolean
5756
*/
5857
protected $result;
5958

60-
//--------------------------------------------------------------------
61-
6259
/**
6360
* Prepares the query against the database, and saves the connection
6461
* info necessary to execute the query later.
@@ -74,18 +71,15 @@ class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface
7471
*/
7572
public function _prepare(string $sql, array $options = [])
7673
{
77-
// @phpstan-ignore-next-line
7874
if (! ($this->statement = $this->db->connID->prepare($sql)))
7975
{
80-
$this->errorCode = $this->db->connID->lastErrorCode(); // @phpstan-ignore-line
81-
$this->errorString = $this->db->connID->lastErrorMsg(); // @phpstan-ignore-line
76+
$this->errorCode = $this->db->connID->lastErrorCode();
77+
$this->errorString = $this->db->connID->lastErrorMsg();
8278
}
8379

8480
return $this;
8581
}
8682

87-
//--------------------------------------------------------------------
88-
8983
/**
9084
* Takes a new set of data and runs it against the currently
9185
* prepared query. Upon success, will return a Results object.
@@ -98,7 +92,7 @@ public function _prepare(string $sql, array $options = [])
9892
*/
9993
public function _execute(array $data): bool
10094
{
101-
if (is_null($this->statement))
95+
if (! isset($this->statement))
10296
{
10397
throw new BadMethodCallException('You must call prepare before trying to execute a prepared statement.');
10498
}
@@ -128,8 +122,6 @@ public function _execute(array $data): bool
128122
return $this->result !== false;
129123
}
130124

131-
//--------------------------------------------------------------------
132-
133125
/**
134126
* Returns the result object for the prepared query.
135127
*
@@ -139,7 +131,4 @@ public function _getResult()
139131
{
140132
return $this->result;
141133
}
142-
143-
//--------------------------------------------------------------------
144-
145134
}

system/Database/Sqlsrv/PreparedQuery.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
*/
5050
class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface
5151
{
52-
5352
/**
5453
* Parameters array used to store the dynamic variables.
5554
*
@@ -64,7 +63,6 @@ class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface
6463
*/
6564
protected $result;
6665

67-
//--------------------------------------------------------------------
6866
/**
6967
* Prepares the query against the database, and saves the connection
7068
* info necessary to execute the query later.
@@ -108,7 +106,7 @@ public function _prepare(string $sql, array $options = [])
108106
*/
109107
public function _execute(array $data): bool
110108
{
111-
if (is_null($this->statement))
109+
if (! isset($this->statement))
112110
{
113111
throw new BadMethodCallException('You must call prepare before trying to execute a prepared statement.');
114112
}
@@ -154,5 +152,4 @@ protected function parameterize(string $queryString): array
154152

155153
return $params;
156154
}
157-
158155
}

0 commit comments

Comments
 (0)