Skip to content

Commit f513207

Browse files
committed
Apply rector fixes
1 parent 05084e2 commit f513207

12 files changed

Lines changed: 21 additions & 22 deletions

src/BaseSeed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ protected function runCall(string $seeder, array $options = []): void
263263

264264
$options += [
265265
'connection' => $connection,
266-
'plugin' => $pluginName ?? ($config !== null ? $config['plugin'] : null),
267-
'source' => $config !== null ? $config['source'] : null,
266+
'plugin' => $pluginName ?? ($config instanceof \Migrations\Config\ConfigInterface ? $config['plugin'] : null),
267+
'source' => $config instanceof \Migrations\Config\ConfigInterface ? $config['source'] : null,
268268
];
269269
$factory = new ManagerFactory([
270270
'connection' => $options['connection'],

src/Command/BakeMigrationDiffCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ protected function getColumns(): void
277277
// changes in columns meta-data
278278
foreach ($currentColumns as $columnName) {
279279
$column = $this->safeGetColumn($currentSchema, $columnName);
280-
if ($column === null || !in_array($columnName, $oldColumns, true)) {
280+
if ($column === null) {
281+
continue;
282+
}
283+
if (!in_array($columnName, $oldColumns, true)) {
281284
continue;
282285
}
283286

src/Command/ResetCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function defaultName(): string
5555
* @param \Cake\Console\ConsoleOptionParser $parser The option parser to configure
5656
* @return \Cake\Console\ConsoleOptionParser
5757
*/
58-
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
58+
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
5959
{
6060
$parser->setDescription([
6161
'Drop all tables and re-run all migrations.',
@@ -116,7 +116,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
116116
// Get tables to drop
117117
$tablesToDrop = $this->getTablesToDrop($connection);
118118

119-
if (empty($tablesToDrop)) {
119+
if ($tablesToDrop === []) {
120120
$io->out('<info>No tables to drop.</info>');
121121
$io->out('');
122122
$io->out('Running migrations...');
@@ -204,7 +204,7 @@ protected function dropTables(AdapterInterface $adapter, array $tables, ConsoleI
204204

205205
try {
206206
foreach ($tables as $table) {
207-
$io->verbose("Dropping table: {$table}");
207+
$io->verbose('Dropping table: ' . $table);
208208
$adapter->dropTable($table);
209209
}
210210
} finally {
@@ -248,12 +248,12 @@ protected function runMigrations(Arguments $args, ConsoleIo $io): ?int
248248
$manager = $factory->createManager($io);
249249
$config = $manager->getConfig();
250250

251-
$io->verbose('<info>using connection</info> ' . (string)$args->getOption('connection'));
251+
$io->verbose('<info>using connection</info> ' . $args->getOption('connection'));
252252
$io->verbose('<info>using paths</info> ' . $config->getMigrationPath());
253253

254254
try {
255255
$start = microtime(true);
256-
$manager->migrate(null, false, null);
256+
$manager->migrate(null, false);
257257
$end = microtime(true);
258258
} catch (Throwable $e) {
259259
$io->err('<error>' . $e->getMessage() . '</error>');

src/Db/Action/AddCheckConstraint.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class AddCheckConstraint extends Action
1515
{
1616
/**
1717
* The check constraint to add
18-
*
19-
* @var \Migrations\Db\Table\CheckConstraint
2018
*/
2119
protected CheckConstraint $checkConstraint;
2220

src/Db/Action/DropCheckConstraint.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class DropCheckConstraint extends Action
1414
{
1515
/**
1616
* The check constraint name to drop
17-
*
18-
* @var string
1917
*/
2018
protected string $constraintName;
2119

src/Db/Adapter/AbstractAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function getConnection(): Connection
194194
$this->connection = $this->getOption('connection');
195195
$this->connect();
196196
}
197-
if ($this->connection === null) {
197+
if (!$this->connection instanceof \Cake\Database\Connection) {
198198
throw new RuntimeException('Unable to establish database connection. Ensure a connection is configured.');
199199
}
200200

src/Db/Adapter/SqliteAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ protected function getChangeColumnInstructions(string $tableName, string $column
11241124
{
11251125
$instructions = $this->beginAlterByCopyTable($tableName);
11261126

1127-
$newColumnName = (string)$newColumn->getName();
1127+
$newColumnName = $newColumn->getName();
11281128
$instructions->addPostStep(function (array $state) use ($columnName, $newColumn): array {
11291129
$dialect = $this->getSchemaDialect();
11301130
$sql = (string)preg_replace(

src/Db/Adapter/SqlserverAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public function disableForeignKeyConstraints(): void
297297
foreach ($rows as $row) {
298298
$constraintName = $this->quoteColumnName($row['constraint_name']);
299299
$tableName = $this->quoteTableName($row['table_name']);
300-
$this->execute("ALTER TABLE {$tableName} DROP CONSTRAINT {$constraintName}");
300+
$this->execute(sprintf('ALTER TABLE %s DROP CONSTRAINT %s', $tableName, $constraintName));
301301
}
302302
}
303303

src/Db/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public function addColumn(string|Column $columnName, ?string $type = null, array
369369
throw new InvalidArgumentException(sprintf(
370370
'An invalid column type "%s" was specified for column "%s".',
371371
$column->getType(),
372-
(string)$column->getName(),
372+
$column->getName(),
373373
));
374374
}
375375

@@ -1186,7 +1186,7 @@ protected function executeActions(bool $exists): void
11861186
}
11871187

11881188
// Only skip CreateTable if we have ONLY view/trigger actions (and at least one)
1189-
if (!$hasViewOrTriggerActions || $hasTableActions || count($actions) === 0) {
1189+
if (!$hasViewOrTriggerActions || $hasTableActions || $actions === []) {
11901190
$this->actions->addAction(new CreateTable($this->table));
11911191
}
11921192
}

src/Util/TableFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function fetchTableName(string $className, ?string $pluginName = null): a
178178
$table = TableRegistry::getTableLocator()->get($className);
179179
foreach ($table->associations()->keys() as $key) {
180180
$association = $table->associations()->get($key);
181-
if ($association !== null && $association->type() === 'belongsToMany') {
181+
if ($association instanceof \Cake\ORM\Association && $association->type() === 'belongsToMany') {
182182
/** @var \Cake\ORM\Association\BelongsToMany $belongsToMany */
183183
$belongsToMany = $association;
184184
$tables[] = $belongsToMany->junction()->getTable();

0 commit comments

Comments
 (0)