Skip to content

Commit 2acd0fb

Browse files
authored
Several fixes from phpstan (#283)
1 parent c6d741a commit 2acd0fb

10 files changed

Lines changed: 58 additions & 12 deletions

src/Command/ImportCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Joomla\Database\Command;
1313

1414
use Joomla\Archive\Archive;
15+
use Joomla\Archive\Exception\UnknownArchiveException;
1516
use Joomla\Console\Command\AbstractCommand;
1617
use Joomla\Database\DatabaseDriver;
1718
use Joomla\Database\Exception\ExecutionFailureException;
@@ -165,7 +166,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in
165166

166167
try {
167168
(new Archive())->extract($zipPath, $folderPath);
168-
} catch (\RuntimeException $e) {
169+
} catch (UnknownArchiveException $e) {
169170
$symfonyStyle->error($e->getMessage());
170171
Folder::delete($folderPath);
171172

src/DatabaseDriver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public static function getConnectors()
240240
$dir = __DIR__;
241241
$iterator = new \DirectoryIterator($dir);
242242

243-
/** @var $file \DirectoryIterator */
243+
/** @var \DirectoryIterator $file */
244244
foreach ($iterator as $file) {
245245
// Only load for php files.
246246
if (!$file->isDir()) {
@@ -250,7 +250,7 @@ public static function getConnectors()
250250
$baseName = $file->getBasename();
251251

252252
// Derive the class name from the type.
253-
/** @var $class DatabaseDriver */
253+
/** @var DatabaseDriver $class */
254254
$class = __NAMESPACE__ . '\\' . ucfirst(strtolower($baseName)) . '\\' . ucfirst(strtolower($baseName)) . 'Driver';
255255

256256
// If the class doesn't exist, or if it's not supported on this system, move on to the next type.
@@ -968,7 +968,7 @@ public function getImporter()
968968
*
969969
* @param boolean $new False to return the current query object, True to return a new DatabaseQuery object.
970970
*
971-
* @return DatabaseQuery
971+
* @return QueryInterface
972972
*
973973
* @since 1.0
974974
*/

src/DatabaseFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getExporter(string $name, ?DatabaseInterface $db = null): Databa
7171
throw new Exception\UnsupportedAdapterException('Database Exporter not found.');
7272
}
7373

74-
/** @var $o DatabaseExporter */
74+
/** @var DatabaseExporter $o */
7575
$o = new $class();
7676

7777
if ($db) {
@@ -103,7 +103,7 @@ public function getImporter(string $name, ?DatabaseInterface $db = null): Databa
103103
throw new Exception\UnsupportedAdapterException('Database importer not found.');
104104
}
105105

106-
/** @var $o DatabaseImporter */
106+
/** @var DatabaseImporter $o */
107107
$o = new $class();
108108

109109
if ($db) {

src/DatabaseImporter.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ protected function getChangeColumnSql($table, \SimpleXMLElement $field)
160160
. $this->getColumnSQL($field);
161161
}
162162

163+
/**
164+
* Get the SQL syntax for a single column that would be included in a table create or alter statement.
165+
*
166+
* @param \SimpleXMLElement $field The XML field definition.
167+
*
168+
* @return string
169+
*
170+
* @since 1.0
171+
*/
172+
abstract protected function getColumnSql(\SimpleXMLElement $field);
173+
163174
/**
164175
* Get the SQL syntax to drop a column.
165176
*

src/DatabaseInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ public function getName();
213213
*/
214214
public function getNullDate();
215215

216+
/**
217+
* Get the common table prefix for the database driver.
218+
*
219+
* @return string The common database table prefix.
220+
*
221+
* @since 3.0
222+
*/
223+
public function getPrefix();
224+
216225
/**
217226
* Get the number of returned rows for the previous executed SQL statement.
218227
*

src/DatabaseQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ public function rightJoin($table, $condition = null)
13631363
*
13641364
* @param string $value The string to measure.
13651365
*
1366-
* @return integer
1366+
* @return string
13671367
*
13681368
* @since 1.0
13691369
*/

src/Mysqli/MysqliStatement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public function closeCursor(): void
333333
/**
334334
* Fetches the SQLSTATE associated with the last operation on the statement handle.
335335
*
336-
* @return string
336+
* @return int
337337
*
338338
* @since 2.0.0
339339
*/
@@ -345,7 +345,7 @@ public function errorCode()
345345
/**
346346
* Fetches extended error information associated with the last operation on the statement handle.
347347
*
348-
* @return array
348+
* @return string
349349
*
350350
* @since 2.0.0
351351
*/

src/Pgsql/PgsqlDriver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ private function getDefaultSchema()
199199
*
200200
* @param mixed $tables A table name or a list of table names.
201201
*
202-
* @return string An empty string because this function is not supported by PostgreSQL.
202+
* @return array An empty array because this function is not supported by PostgreSQL.
203203
*
204204
* @since 1.5.0
205205
* @throws \RuntimeException
206206
*/
207207
public function getTableCreate($tables)
208208
{
209-
return '';
209+
return [];
210210
}
211211

212212
/**

src/QueryInterface.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,31 @@ public function isNullDatetime($column);
435435
*/
436436
public function order($columns);
437437

438+
/**
439+
* Wrap an SQL statement identifier name such as column, table or database names in quotes to prevent injection
440+
* risks and reserved word conflicts.
441+
*
442+
* This method is provided for use where the query object is passed to a function for modification.
443+
* If you have direct access to the database object, it is recommended you use the quoteName method directly.
444+
*
445+
* Note that 'qn' is an alias for this method as it is in DatabaseDriver.
446+
*
447+
* Usage:
448+
* $query->quoteName('#__a');
449+
* $query->qn('#__a');
450+
*
451+
* @param array|string $name The identifier name to wrap in quotes, or an array of identifier names to wrap in quotes.
452+
* Each type supports dot-notation name.
453+
* @param array|string $as The AS query part associated to $name. It can be string or array, in latter case it has to be
454+
* same length of $name; if is null there will not be any AS part for string or array element.
455+
*
456+
* @return array|string The quote wrapped name, same type of $name.
457+
*
458+
* @since 1.0
459+
* @throws \RuntimeException if the internal db property is not a valid object.
460+
*/
461+
public function quoteName($name, $as = null);
462+
438463
/**
439464
* Get the function to return a random floating-point value
440465
*

src/Sqlsrv/SqlsrvQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public function currentTimestamp()
312312
*
313313
* @param string $value The string to measure.
314314
*
315-
* @return integer
315+
* @return string
316316
*
317317
* @since 1.0
318318
*/

0 commit comments

Comments
 (0)