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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"stan-setup": "phive install",
"lowest": "validate-prefer-lowest",
"lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json",
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.3.1\" phpstan/phpstan:\"~2.1.40\" && mv composer.backup composer.json",
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.7.0\" phpstan/phpstan:\"~2.3.0\" && mv composer.backup composer.json",
"rector-check": "vendor/bin/rector process --dry-run",
"rector-fix": "vendor/bin/rector process",
"test": "phpunit",
Expand Down
9 changes: 9 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@

<rule ref="./vendor/cakephp/cakephp-codesniffer/CakePHP/ruleset.xml"/>

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<include-pattern>*/src/*</include-pattern>
<include-pattern>*/tests/*</include-pattern>
<properties>
<property name="linesCountBeforeDeclare" value="0"/>
<property name="linesCountAfterDeclare" value="1"/>
<property name="spacesCountAroundEqualsSign" value="0"/>
</properties>
</rule>
<!-- Necessary for class aliases used for backwards compat -->
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<severity>0</severity>
Expand Down
12 changes: 10 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector;
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\CodeQuality\Rector\If_\ArrayExplicitBoolCompareRector;
use Rector\CodeQuality\Rector\If_\ObjectExplicitBoolCompareRector;
use Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector;
use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveDuplicatedReturnSelfDocblockRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveMixedDocblockOverruledByNativeTypeRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessUnionReturnDocblockRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Set\ValueObject\SetList;
Expand Down Expand Up @@ -49,6 +53,10 @@
ReturnTypeFromStrictFluentReturnRector::class,
SplitDoubleAssignRector::class,
NewlineAfterStatementRector::class,
ExplicitBoolCompareRector::class,
TypedPropertyFromCreateMockAssignRector::class,
ArrayExplicitBoolCompareRector::class,
ObjectExplicitBoolCompareRector::class,
RemoveUselessUnionReturnDocblockRector::class,
RemoveMixedDocblockOverruledByNativeTypeRector::class,
RemoveDuplicatedReturnSelfDocblockRector::class,
]);
16 changes: 4 additions & 12 deletions src/Command/BakeMigrationDiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,7 @@ protected function getColumns(): void
if ($attribute === 'length') {
$phinxAttributeName = 'limit';
}
if (!isset($changedAttributes[$phinxAttributeName])) {
$changedAttributes[$phinxAttributeName] = $column[$attribute];
}
$changedAttributes[$phinxAttributeName] ??= $column[$attribute];
}

// Only convert unsigned to signed if it actually changed
Expand Down Expand Up @@ -352,9 +350,7 @@ protected function getColumns(): void
unset($changedAttributes['limit']);
} elseif (isset($changedAttributes['length'])) {
// For non-decimal columns, convert 'length' to 'limit'
if (!isset($changedAttributes['limit'])) {
$changedAttributes['limit'] = $changedAttributes['length'];
}
$changedAttributes['limit'] ??= $changedAttributes['length'];
unset($changedAttributes['length']);
}

Expand All @@ -363,9 +359,7 @@ protected function getColumns(): void
}

// columns deletion
if (!isset($this->templateData[$table]['columns']['remove'])) {
$this->templateData[$table]['columns']['remove'] = [];
}
$this->templateData[$table]['columns']['remove'] ??= [];
$removedColumns = array_diff($oldColumns, $currentColumns);
foreach ($removedColumns as $columnName) {
$column = $this->safeGetColumn($this->dumpSchema[$table], $columnName);
Expand Down Expand Up @@ -484,9 +478,7 @@ protected function getIndexes(): void
}

// indexes deletion
if (!isset($this->templateData[$table]['indexes']['remove'])) {
$this->templateData[$table]['indexes']['remove'] = [];
}
$this->templateData[$table]['indexes']['remove'] ??= [];

$removedIndexes = array_diff($oldIndexes, $currentIndexes);
$parts = [];
Expand Down
14 changes: 6 additions & 8 deletions src/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,12 @@ protected function mapColumnData(array $data): array
break;
}
}
if ($data['length'] === null) {
$data['length'] = match ($data['type']) {
self::PHINX_TYPE_TINYBLOB => TableSchema::LENGTH_TINY,
self::PHINX_TYPE_MEDIUMBLOB => TableSchema::LENGTH_MEDIUM,
self::PHINX_TYPE_LONGBLOB => TableSchema::LENGTH_LONG,
default => null,
};
}
$data['length'] ??= match ($data['type']) {
self::PHINX_TYPE_TINYBLOB => TableSchema::LENGTH_TINY,
self::PHINX_TYPE_MEDIUMBLOB => TableSchema::LENGTH_MEDIUM,
self::PHINX_TYPE_LONGBLOB => TableSchema::LENGTH_LONG,
default => null,
};
$data['type'] = 'binary';
} elseif ($data['type'] === self::TYPE_INTEGER) {
if (isset($data['length']) && $data['length'] === self::INT_BIG) {
Expand Down
2 changes: 1 addition & 1 deletion src/Db/Adapter/SqliteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ protected function bufferIndicesAndTriggers(AlterInstructions $instructions, str
case 'index':
$info = $indexMap[$row['name']];
$columns = array_map(
function ($column) {
function ($column): ?string {
if ($column === null) {
return null;
}
Expand Down
28 changes: 7 additions & 21 deletions src/Db/Plan/Plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,10 @@ protected function gatherUpdates(array $actions): void
$name = $table->getName();

if ($action instanceof RemoveColumn) {
if (!isset($this->columnRemoves[$name])) {
$this->columnRemoves[$name] = new AlterTable($table);
}
$this->columnRemoves[$name] ??= new AlterTable($table);
$this->columnRemoves[$name]->addAction($action);
} else {
if (!isset($this->tableUpdates[$name])) {
$this->tableUpdates[$name] = new AlterTable($table);
}
$this->tableUpdates[$name] ??= new AlterTable($table);
$this->tableUpdates[$name]->addAction($action);
}
}
Expand All @@ -465,9 +461,7 @@ protected function gatherTableMoves(array $actions): void
$table = $action->getTable();
$name = $table->getName();

if (!isset($this->tableMoves[$name])) {
$this->tableMoves[$name] = new AlterTable($table);
}
$this->tableMoves[$name] ??= new AlterTable($table);

$this->tableMoves[$name]->addAction($action);
}
Expand All @@ -492,9 +486,7 @@ protected function gatherIndexes(array $actions): void
$table = $action->getTable();
$name = $table->getName();

if (!isset($this->indexes[$name])) {
$this->indexes[$name] = new AlterTable($table);
}
$this->indexes[$name] ??= new AlterTable($table);

$this->indexes[$name]->addAction($action);
}
Expand Down Expand Up @@ -522,9 +514,7 @@ protected function gatherConstraints(array $actions): void
$table = $action->getTable();
$name = $table->getName();

if (!isset($this->constraints[$name])) {
$this->constraints[$name] = new AlterTable($table);
}
$this->constraints[$name] ??= new AlterTable($table);

$this->constraints[$name]->addAction($action);
}
Expand Down Expand Up @@ -553,9 +543,7 @@ protected function gatherPartitions(array $actions): void
$table = $action->getTable();
$name = $table->getName();

if (!isset($this->partitions[$name])) {
$this->partitions[$name] = new AlterTable($table);
}
$this->partitions[$name] ??= new AlterTable($table);

$this->partitions[$name]->addAction($action);
}
Expand All @@ -581,9 +569,7 @@ protected function gatherViewsAndTriggers(array $actions): void
$table = $action->getTable();
$name = $table->getName();

if (!isset($this->viewsAndTriggers[$name])) {
$this->viewsAndTriggers[$name] = new AlterTable($table);
}
$this->viewsAndTriggers[$name] ??= new AlterTable($table);

$this->viewsAndTriggers[$name]->addAction($action);
}
Expand Down
4 changes: 1 addition & 3 deletions src/TestSuite/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ public function runMany(

$options[$i] = $migrationSet;
$connectionName = $migrationSet['connection'];
if (!isset($connectionsList[$connectionName])) {
$connectionsList[$connectionName] = ['name' => $connectionName, 'skip' => $skip];
}
$connectionsList[$connectionName] ??= ['name' => $connectionName, 'skip' => $skip];

// Sets sharing a connection and a plugin also share a migration history,
// while each of them only has its own source directory on disk. Group
Expand Down
5 changes: 1 addition & 4 deletions src/View/Helper/MigrationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,7 @@ public function getColumnOption(array $options): array
} else {
// Convert CakePHP's precision (decimal places) to Migrations' scale
// Only convert if scale is not already set (for decimal columns from diff)
if (!isset($columnOptions['scale'])) {
$columnOptions['scale'] = $columnOptions['precision'];
}

$columnOptions['scale'] ??= $columnOptions['precision'];
if (isset($columnOptions['limit'])) {
$columnOptions['precision'] = $columnOptions['limit'];
unset($columnOptions['limit']);
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixture/ArticlesFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixture/CategoriesFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixture/CompositePkFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixture/EventsFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Migrations\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixture/OrdersFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixture/PartsFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixture/ProductsFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixture/SpecialPkFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixture/SpecialTagsFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixture/TextsFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Migrations\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixture/UsersFixture.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
Expand Down
5 changes: 0 additions & 5 deletions tests/TestCase/Command/EntryCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ class EntryCommandTest extends TestCase
{
use ConsoleIntegrationTestTrait;

protected function setUp(): void
{
parent::setUp();
}

/**
* Test execute() generating help
*
Expand Down
4 changes: 1 addition & 3 deletions tests/TestCase/Db/Adapter/PostgresAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ private function isPostgresAvailable()
{
static $available;

if ($available === null) {
$available = in_array('pgsql', PDO::getAvailableDrivers(), true);
}
$available ??= in_array('pgsql', PDO::getAvailableDrivers(), true);

return $available;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Migrations\BaseMigration;

class Migrator extends BaseMigration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Migrations\BaseMigration;

class Migrator2 extends BaseMigration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Migrations\BaseSeed;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Migrations\BaseSeed;

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/test_app/config/AltSeeds/AnotherNumbersSeed.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Migrations\BaseSeed;

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/test_app/config/AltSeeds/NumbersAltSeed.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Migrations\BaseSeed;

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/test_app/config/CallSeeds/DatabaseSeed.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Migrations\BaseSeed;

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/test_app/config/CallSeeds/LettersSeed.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Migrations\BaseSeed;

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/test_app/config/CallSeeds/NumbersCallSeed.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Migrations\BaseSeed;

/**
Expand Down
Loading
Loading