Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/CakeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function rollbackToDateTime(string $environment, DateTime $dateTime, bool
sort($versions);
$versions = array_reverse($versions);

if (empty($versions) || $dateString > $versions[0]) {
if (!$versions || $dateString > $versions[0]) {
$this->getOutput()->writeln('No migrations to rollback');

return;
Expand Down Expand Up @@ -218,7 +218,7 @@ public function markMigrated(int $version, string $path): bool

$migrationFile = glob($path . DS . $version . '*');

if (empty($migrationFile)) {
if (!$migrationFile) {
throw new RuntimeException(
sprintf('A migration file matching version number `%s` could not be found', $version)
);
Expand Down Expand Up @@ -254,13 +254,13 @@ public function getVersionsToMark(InputInterface $input): array
$versionArg = $input->getArgument('version');
$targetArg = $input->getOption('target');
$hasAllVersion = in_array($versionArg, ['all', '*'], true);
if ((empty($versionArg) && empty($targetArg)) || $hasAllVersion) {
if ((!$versionArg && !$targetArg) || $hasAllVersion) {
return $versions;
}

$version = (int)$targetArg ?: (int)$versionArg;

if ($input->getOption('only') || !empty($versionArg)) {
if ($input->getOption('only') || $versionArg) {
if (!in_array($version, $versions)) {
throw new InvalidArgumentException("Migration `$version` was not found !");
}
Expand Down Expand Up @@ -375,7 +375,7 @@ public function setInput(InputInterface $input)
public function getSeeds(string $environment): array
{
parent::getSeeds($environment);
if (empty($this->seeds)) {
if (!$this->seeds) {
return [];
}

Expand Down
4 changes: 2 additions & 2 deletions src/Command/BakeMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function templateData(Arguments $arguments): array
$this->io->abort('When applying fields the migration name should start with one of the following prefixes: `Create`, `Drop`, `Add`, `Remove`, `Alter`. See: https://book.cakephp.org/migrations/4/en/index.html#migrations-file-name');
}

if (empty($action)) {
if (!$action) {
return [
'plugin' => $this->plugin,
'pluginPath' => $pluginPath,
Expand All @@ -103,7 +103,7 @@ public function templateData(Arguments $arguments): array
];
}

if (in_array($action[0], ['alter_table', 'add_field'], true) && !empty($primaryKey)) {
if (in_array($action[0], ['alter_table', 'add_field'], true) && $primaryKey) {
/** @psalm-suppress PossiblyNullReference */
$this->io->abort('Adding a primary key to an already existing table is not supported.');
}
Expand Down
16 changes: 8 additions & 8 deletions src/Command/BakeMigrationDiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function bake(string $name, Arguments $args, ConsoleIo $io): void
'Make sure all your migrations have been migrated before baking a diff.');
}

if (empty($this->migrationsFiles) && empty($this->migratedItems)) {
if (!$this->migrationsFiles && !$this->migratedItems) {
$this->bakeSnapshot($name, $args, $io);
}

Expand Down Expand Up @@ -322,7 +322,7 @@ protected function getColumns(): void
$this->templateData[$table]['columns']['remove'] = [];
}
$removedColumns = array_diff($oldColumns, $currentColumns);
if (!empty($removedColumns)) {
if ($removedColumns) {
foreach ($removedColumns as $columnName) {
$column = $this->dumpSchema[$table]->getColumn($columnName);
/** @var int $key */
Expand Down Expand Up @@ -440,7 +440,7 @@ protected function getIndexes(): void

$removedIndexes = array_diff($oldIndexes, $currentIndexes);
$parts = [];
if (!empty($removedIndexes)) {
if ($removedIndexes) {
foreach ($removedIndexes as $index) {
$parts[$index] = $this->dumpSchema[$table]->getIndex($index);
}
Expand All @@ -459,11 +459,11 @@ protected function getIndexes(): void
*/
protected function checkSync(): bool
{
if (empty($this->migrationsFiles) && empty($this->migratedItems)) {
if (!$this->migrationsFiles && !$this->migratedItems) {
return true;
}

if (!empty($this->migratedItems)) {
if ($this->migratedItems) {
$lastVersion = $this->migratedItems[0]['version'];
$lastFile = end($this->migrationsFiles);

Expand Down Expand Up @@ -513,15 +513,15 @@ protected function getDumpSchema(Arguments $args): array
$inputArgs = [];

$connectionName = 'default';
if (!empty($args->getOption('connection'))) {
if ($args->getOption('connection')) {
$connectionName = $inputArgs['--connection'] = $args->getOption('connection');
}

if ($args->getOption('source')) {
$inputArgs['--source'] = $args->getOption('source');
}

if (!empty($args->getOption('plugin'))) {
if ($args->getOption('plugin')) {
$inputArgs['--plugin'] = $args->getOption('plugin');
}

Expand Down Expand Up @@ -551,7 +551,7 @@ protected function getCurrentSchema(): array
{
$schema = [];

if (empty($this->tables)) {
if (!$this->tables) {
return $schema;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Command/BakeSimpleMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
}
$this->extractCommonProperties($args);
$name = $args->getArgumentAt(0);
if (empty($name)) {
if (!$name) {
$io->err('You must provide a name to bake a ' . $this->name());
$this->abort();
}
Expand Down Expand Up @@ -193,7 +193,7 @@ protected function createFile(string $path, string $contents, Arguments $args, C
*/
protected function getMigrationName(?string $name = null): string
{
if (empty($name)) {
if (!$name) {
/** @psalm-suppress PossiblyNullReference */
$this->io->abort('Choose a migration name to bake in CamelCase format');
}
Expand All @@ -203,7 +203,7 @@ protected function getMigrationName(?string $name = null): string

if (!preg_match('/^[A-Z]{1}[a-zA-Z0-9]+$/', $name)) {
/** @psalm-suppress PossiblyNullReference */
$this->io->abort('The className is not correct. The className can only contain "A-Z" and "0-9".');
$this->io->abort('The className is not correct. The className can only contain "A-Z" and "0-9" and has to start with a letter.');
}

return $name;
Expand Down
6 changes: 3 additions & 3 deletions src/Command/MigrationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getOptionParser(): ConsoleOptionParser
$parser->setDescription($command->getDescription());
$definition = $command->getDefinition();
foreach ($definition->getOptions() as $option) {
if (!empty($option->getShortcut())) {
if ($option->getShortcut()) {
$parser->addOption($option->getName(), [
'short' => $option->getShortcut(),
'help' => $option->getDescription(),
Expand Down Expand Up @@ -140,12 +140,12 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
$exitCode === 0
) {
$newArgs = [];
if (!empty($args->getOption('connection'))) {
if ($args->getOption('connection')) {
$newArgs[] = '-c';
$newArgs[] = $args->getOption('connection');
}

if (!empty($args->getOption('plugin'))) {
if ($args->getOption('plugin')) {
$newArgs[] = '-p';
$newArgs[] = $args->getOption('plugin');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Phinx/CacheBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return static::CODE_ERROR;
}
$tables = [$name];
if (empty($name)) {
if (!$name) {
$tables = $schema->listTables();
}
foreach ($tables as $table) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Phinx/CacheClear.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return static::CODE_ERROR;
}
$tables = [$name];
if (empty($name)) {
if (!$name) {
$tables = $schema->listTables();
}
$cacher = $schema->getCacher();
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Phinx/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
[$phinxTimestamp, $phinxName] = explode('_', Util::mapClassNameToFileName($name), 2);
$migrationFilename = glob($migrationPath . '*' . $phinxName);

if (empty($migrationFilename)) {
if (!$migrationFilename) {
$output->writeln('<info>An error occurred while renaming file</info>');
} else {
$migrationFilename = $migrationFilename[0];
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Phinx/Seed.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$seed = $input->getOption('seed');
if (!empty($seed) && !is_array($seed)) {
if ($seed && !is_array($seed)) {
$input->setOption('seed', [$seed]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Command/Phinx/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected function display(array $migrations): void
{
$output = $this->getManager()->getOutput();

if (!empty($migrations)) {
if ($migrations) {
$output->writeln('');
$output->writeln(' Status Migration ID Migration Name ');
$output->writeln('-----------------------------------------');
Expand Down
2 changes: 1 addition & 1 deletion src/Command/SeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected function executeSeeds(Arguments $args, ConsoleIo $io): ?int
$io->out('<info>ordering by</info> ' . $versionOrder . ' time');

$start = microtime(true);
if (empty($seeds)) {
if (!$seeds) {
// run all the seed(ers)
$manager->seed();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
*/
protected function display(array $migrations, ConsoleIo $io): void
{
if (!empty($migrations)) {
if ($migrations) {
$rows = [];
$rows[] = ['Status', 'Migration ID', 'Migration Name'];

Expand Down
2 changes: 1 addition & 1 deletion src/Db/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ public function execute(string $sql, array $params = []): int
}

$connection = $this->getConnection();
if (empty($params)) {
if (!$params) {
$result = $connection->execute($sql);

return $result->rowCount();
Expand Down
8 changes: 4 additions & 4 deletions src/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ protected function getChangePrimaryKeyInstructions(Table $table, $newColumns): A
}

// Add the primary key(s)
if (!empty($newColumns)) {
if ($newColumns) {
$sql = 'ADD PRIMARY KEY (';
if (is_string($newColumns)) { // handle primary_key => 'id'
$sql .= $this->quoteColumnName($newColumns);
Expand Down Expand Up @@ -449,7 +449,7 @@ protected function getAddColumnInstructions(Table $table, Column $column): Alter
protected function afterClause(Column $column): string
{
$after = $column->getAfter();
if (empty($after)) {
if (!$after) {
return '';
}

Expand Down Expand Up @@ -815,7 +815,7 @@ protected function getDropForeignKeyByColumnsInstructions(string $tableName, arr
}
}

if (empty($matches)) {
if (!$matches) {
throw new InvalidArgumentException(sprintf(
'No foreign key on column(s) `%s` exists',
implode(', ', $columns)
Expand Down Expand Up @@ -1219,7 +1219,7 @@ public function hasDatabase(string $name): bool
)->fetchAll('assoc');

foreach ($rows as $row) {
if (!empty($row)) {
if ($row) {
return true;
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ public function createTable(Table $table, array $columns = [], array $indexes =
$queries[] = $sql;

// process column comments
if (!empty($this->columnsWithComments)) {
if ($this->columnsWithComments) {
foreach ($this->columnsWithComments as $column) {
$queries[] = $this->getColumnCommentSqlDefinition($column, $table->getName());
}
}

// set the indexes
if (!empty($indexes)) {
if ($indexes) {
foreach ($indexes as $index) {
$queries[] = $this->getIndexSqlDefinition($index, $table->getName());
}
Expand Down Expand Up @@ -227,7 +227,7 @@ protected function getChangePrimaryKeyInstructions(Table $table, array|string|nu
}

// Add the new primary key
if (!empty($newColumns)) {
if ($newColumns) {
$sql = sprintf(
'ADD CONSTRAINT %s PRIMARY KEY (',
$this->quoteColumnName($parts['table'] . '_pkey')
Expand Down Expand Up @@ -698,7 +698,7 @@ protected function getDropIndexByColumnsInstructions(string $tableName, $columns
$indexes = $this->getIndexes($tableName);
foreach ($indexes as $indexName => $index) {
$a = array_diff($columns, $index['columns']);
if (empty($a)) {
if (!$a) {
return new AlterInstructions([], [sprintf(
'DROP INDEX IF EXISTS %s',
'"' . ($parts['schema'] . '".' . $this->quoteColumnName($indexName))
Expand Down Expand Up @@ -733,8 +733,7 @@ protected function getDropIndexByNameInstructions(string $tableName, string $ind
public function hasPrimaryKey(string $tableName, $columns, ?string $constraint = null): bool
{
$primaryKey = $this->getPrimaryKey($tableName);

if (empty($primaryKey)) {
if (!$primaryKey) {
return false;
}

Expand Down Expand Up @@ -871,7 +870,7 @@ protected function getDropForeignKeyByColumnsInstructions(string $tableName, arr
}
}

if (empty($matches)) {
if (!$matches) {
throw new InvalidArgumentException(sprintf(
'No foreign key on column(s) `%s` exists',
implode(', ', $columns)
Expand Down
4 changes: 2 additions & 2 deletions src/Db/Adapter/SqliteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,15 @@ protected function getChangePrimaryKeyInstructions(Table $table, $newColumns): A

// Drop the existing primary key
$primaryKey = $this->getPrimaryKey($table->getName());
if (!empty($primaryKey)) {
if ($primaryKey) {
$instructions->merge(
// FIXME: array access is a hack to make this incomplete implementation work with a correct getPrimaryKey implementation
$this->getDropPrimaryKeyInstructions($table, $primaryKey[0])
);
}

// Add the primary key(s)
if (!empty($newColumns)) {
if ($newColumns) {
if (!is_string($newColumns)) {
throw new InvalidArgumentException(sprintf(
'Invalid value for primary key: %s',
Expand Down
Loading
Loading