Skip to content

Commit 0ebbec0

Browse files
committed
👽 Fix some deprecations, remove useles imports
- `fetch` => `fetchAssociative` - `getPrimaryKeyColumns` => `getPrimaryKey()->getUnquotedColumns()` - `exec` => `executeStatement`
1 parent 81791c3 commit 0ebbec0

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

src/DbRow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function _dbLoadIfNotLoaded(): void
198198
$sql = 'SELECT * FROM '.$connection->quoteIdentifier($this->dbTableName).' WHERE '.$sql_where;
199199
$result = $connection->executeQuery($sql, $parameters);
200200

201-
$row = $result->fetch(\PDO::FETCH_ASSOC);
201+
$row = $result->fetchAssociative();
202202

203203
if ($row === false) {
204204
throw new TDBMException("Could not retrieve object from table \"$this->dbTableName\" using filter \".$sql_where.\" with data \"".var_export($parameters, true)."\".");

src/QueryFactory/FindObjectsFromRawSqlQueryFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ private function formatSelect(array $baseSelect): array
232232
}
233233

234234
$table = $this->schema->getTable($tableName);
235-
$pkColumns = $table->getPrimaryKeyColumns();
235+
$primaryKey = $table->getPrimaryKey();
236+
assert($primaryKey !== null, 'TDBM Only works on tables with primary keys');
237+
$pkColumns = $primaryKey->getUnquotedColumns();
236238
foreach ($table->getColumns() as $column) {
237239
$columnName = $column->getName();
238240
$alias = AbstractQueryFactory::getColumnAlias($tableName, $columnName);
@@ -252,7 +254,7 @@ private function formatSelect(array $baseSelect): array
252254
]
253255
];
254256
$formattedSelect[] = $astColumn;
255-
if (array_key_exists($columnName, $pkColumns)) {
257+
if (in_array($columnName, $pkColumns, true)) {
256258
$formattedCountSelect[] = $astColumn;
257259
}
258260
$columnDescriptors[$alias] = [

tests/Performance/ManyToOneBench.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
namespace TheCodingMachine\TDBM\Performance;
44

55
use Doctrine\Common\Cache\ArrayCache;
6-
use Doctrine\Common\Cache\VoidCache;
76
use Doctrine\DBAL\Connection;
87
use Mouf\Database\SchemaAnalyzer\SchemaAnalyzer;
98
use PhpBench\Benchmark\Metadata\Annotations\Iterations;
109
use TheCodingMachine\FluidSchema\TdbmFluidSchema;
1110
use TheCodingMachine\TDBM\Configuration;
1211
use TheCodingMachine\TDBM\ConfigurationInterface;
1312
use TheCodingMachine\TDBM\ConnectionFactory;
14-
use TheCodingMachine\TDBM\DummyGeneratorListener;
1513
use TheCodingMachine\TDBM\SchemaLockFileDumper;
1614
use TheCodingMachine\TDBM\TDBMAbstractServiceTest;
1715
use TheCodingMachine\TDBM\TDBMSchemaAnalyzer;
@@ -70,7 +68,7 @@ private static function initSchema(Connection $connection): void
7068
$sqlStmts = $toSchema->getMigrateFromSql($fromSchema, $connection->getDatabasePlatform());
7169

7270
foreach ($sqlStmts as $sqlStmt) {
73-
$connection->exec($sqlStmt);
71+
$connection->executeStatement($sqlStmt);
7472
}
7573

7674
for ($i = 1; $i < 200; $i++) {

tests/TDBMAbstractServiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,12 @@ private static function initSchema(Connection $connection): void
444444

445445
foreach ($sqlStmts as $sqlStmt) {
446446
//echo $sqlStmt."\n";
447-
$connection->exec($sqlStmt);
447+
$connection->executeStatement($sqlStmt);
448448
}
449449

450450
// Let's generate computed columns
451451
if ($connection->getDatabasePlatform() instanceof MySqlPlatform && !self::isMariaDb($connection)) {
452-
$connection->exec('CREATE TABLE `players` (
452+
$connection->executeStatement('CREATE TABLE `players` (
453453
`id` INT UNSIGNED AUTO_INCREMENT NOT NULL,
454454
`player_and_games` JSON NOT NULL,
455455
`names_virtual` VARCHAR(20) GENERATED ALWAYS AS (`player_and_games` ->> \'$.name\') NOT NULL COMMENT \'@ReadOnly\',

tests/Utils/BeanDescriptorTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222

2323
namespace TheCodingMachine\TDBM\Utils;
2424

25-
use Doctrine\Common\Cache\ArrayCache;
2625
use Doctrine\Common\Cache\VoidCache;
2726
use Doctrine\DBAL\Schema\Schema;
2827
use Doctrine\DBAL\Schema\Table;
29-
use Doctrine\DBAL\Types\Type;
3028
use Doctrine\DBAL\Types\Types;
3129
use Mouf\Database\SchemaAnalyzer\SchemaAnalyzer;
3230
use TheCodingMachine\TDBM\Configuration;

0 commit comments

Comments
 (0)