diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d6a596c9..36133770 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -54,6 +54,24 @@ parameters: count: 1 path: src/Db/Adapter/SqliteAdapter.php + - + message: '#^Call to an undefined method Migrations\\Db\\Table\\Index\:\:setUnique\(\)\.$#' + identifier: method.notFound + count: 1 + path: src/Db/Table/Index.php + + - + message: '#^Call to an undefined method Migrations\\MigrationInterface\:\:down\(\)\.$#' + identifier: method.notFound + count: 1 + path: src/Migration/Environment.php + + - + message: '#^Call to an undefined method Migrations\\MigrationInterface\:\:up\(\)\.$#' + identifier: method.notFound + count: 1 + path: src/Migration/Environment.php + - message: '#^Call to function method_exists\(\) with Migrations\\MigrationInterface and ''useTransactions'' will always evaluate to true\.$#' identifier: function.alreadyNarrowedType diff --git a/src/Db/Adapter/AdapterInterface.php b/src/Db/Adapter/AdapterInterface.php index 057eace4..6585e153 100644 --- a/src/Db/Adapter/AdapterInterface.php +++ b/src/Db/Adapter/AdapterInterface.php @@ -32,54 +32,24 @@ interface AdapterInterface public const PHINX_TYPE_TINY_INTEGER = TableSchemaInterface::TYPE_TINYINTEGER; public const PHINX_TYPE_SMALL_INTEGER = TableSchemaInterface::TYPE_SMALLINTEGER; public const PHINX_TYPE_BIG_INTEGER = TableSchemaInterface::TYPE_BIGINTEGER; - - /** @deprecated Use smallinteger or boolean instead */ - public const PHINX_TYPE_BIT = 'bit'; - public const PHINX_TYPE_FLOAT = TableSchemaInterface::TYPE_FLOAT; public const PHINX_TYPE_DECIMAL = TableSchemaInterface::TYPE_DECIMAL; - - /** @deprecated Use float instead */ - public const PHINX_TYPE_DOUBLE = 'double'; - public const PHINX_TYPE_DATETIME = TableSchemaInterface::TYPE_DATETIME; public const PHINX_TYPE_TIMESTAMP = TableSchemaInterface::TYPE_TIMESTAMP; public const PHINX_TYPE_TIME = TableSchemaInterface::TYPE_TIME; public const PHINX_TYPE_DATE = TableSchemaInterface::TYPE_DATE; public const PHINX_TYPE_BINARY = TableSchemaInterface::TYPE_BINARY; - - /** @deprecated Use binary instead */ - public const PHINX_TYPE_VARBINARY = 'varbinary'; - public const PHINX_TYPE_BINARYUUID = TableSchemaInterface::TYPE_BINARY_UUID; - - /** @deprecated Use binary instead */ - public const PHINX_TYPE_BLOB = 'blob'; - - /** @deprecated Use binary with length instead */ - public const PHINX_TYPE_TINYBLOB = 'tinyblob'; // Specific to Mysql. - - /** @deprecated Use binary with length instead */ - public const PHINX_TYPE_MEDIUMBLOB = 'mediumblob'; // Specific to Mysql - - /** @deprecated Use binary with length instead */ - public const PHINX_TYPE_LONGBLOB = 'longblob'; // Specific to Mysql public const PHINX_TYPE_BOOLEAN = TableSchemaInterface::TYPE_BOOLEAN; public const PHINX_TYPE_JSON = TableSchemaInterface::TYPE_JSON; public const PHINX_TYPE_UUID = TableSchemaInterface::TYPE_UUID; public const PHINX_TYPE_NATIVEUUID = TableSchemaInterface::TYPE_NATIVE_UUID; - /** @deprecated Use json instead */ - public const PHINX_TYPE_JSONB = 'jsonb'; - /** @deprecated Use blob instead */ - public const PHINX_TYPE_FILESTREAM = 'filestream'; // Geospatial database types public const PHINX_TYPE_GEOMETRY = TableSchemaInterface::TYPE_GEOMETRY; public const PHINX_TYPE_POINT = TableSchemaInterface::TYPE_POINT; public const PHINX_TYPE_LINESTRING = TableSchemaInterface::TYPE_LINESTRING; public const PHINX_TYPE_POLYGON = TableSchemaInterface::TYPE_POLYGON; - /** @deprecated Will be removed in 5.x */ - public const PHINX_TYPE_GEOGRAPHY = 'geography'; public const PHINX_TYPES_GEOSPATIAL = [ self::PHINX_TYPE_GEOMETRY, @@ -88,16 +58,6 @@ interface AdapterInterface self::PHINX_TYPE_POLYGON, ]; - // only for mysql so far - /** @deprecated Will be removed in 5.x */ - public const PHINX_TYPE_MEDIUM_INTEGER = 'mediuminteger'; - - /** @deprecated Will be removed in 5.x */ - public const PHINX_TYPE_ENUM = 'enum'; - - /** @deprecated Will be removed in 5.x */ - public const PHINX_TYPE_SET = 'set'; - // only for mysql so far // TODO This can be aliased to TableSchema constants with cakephp 5.3 public const PHINX_TYPE_YEAR = 'year'; diff --git a/src/Db/Adapter/MysqlAdapter.php b/src/Db/Adapter/MysqlAdapter.php index 5c0dd5d0..5fe52840 100644 --- a/src/Db/Adapter/MysqlAdapter.php +++ b/src/Db/Adapter/MysqlAdapter.php @@ -28,15 +28,9 @@ class MysqlAdapter extends AbstractAdapter * @var string[] */ protected static array $specificColumnTypes = [ - self::PHINX_TYPE_ENUM, - self::PHINX_TYPE_SET, self::PHINX_TYPE_YEAR, self::PHINX_TYPE_JSON, self::PHINX_TYPE_BINARYUUID, - self::PHINX_TYPE_TINYBLOB, - self::PHINX_TYPE_MEDIUMBLOB, - self::PHINX_TYPE_LONGBLOB, - self::PHINX_TYPE_MEDIUM_INTEGER, ]; // These constants roughly correspond to the maximum allowed value for each field, @@ -267,23 +261,7 @@ protected function mapColumnData(array $data): array default => null, }; } - $binaryTypes = [ - self::PHINX_TYPE_BLOB, - self::PHINX_TYPE_TINYBLOB, - self::PHINX_TYPE_MEDIUMBLOB, - self::PHINX_TYPE_LONGBLOB, - self::PHINX_TYPE_VARBINARY, - self::PHINX_TYPE_BINARY, - ]; - if (in_array($data['type'], $binaryTypes, true)) { - if (!isset($data['length'])) { - $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 => $data['length'], - }; - } + if ($data['type'] === self::PHINX_TYPE_BINARY) { if ($data['length'] === self::BLOB_REGULAR) { $data['type'] = TableSchema::TYPE_BINARY; $data['length'] = null; @@ -305,9 +283,6 @@ protected function mapColumnData(array $data): array unset($data['length']); } unset($data['length']); - } elseif ($data['type'] == self::PHINX_TYPE_DOUBLE) { - $data['type'] = TableSchema::TYPE_FLOAT; - $data['length'] = 52; } return $data; diff --git a/src/Db/Adapter/PostgresAdapter.php b/src/Db/Adapter/PostgresAdapter.php index 14793cb4..8ace8efb 100644 --- a/src/Db/Adapter/PostgresAdapter.php +++ b/src/Db/Adapter/PostgresAdapter.php @@ -35,7 +35,6 @@ class PostgresAdapter extends AbstractAdapter */ protected static array $specificColumnTypes = [ self::PHINX_TYPE_JSON, - self::PHINX_TYPE_JSONB, self::PHINX_TYPE_CIDR, self::PHINX_TYPE_INET, self::PHINX_TYPE_MACADDR, diff --git a/src/Db/Adapter/SqliteAdapter.php b/src/Db/Adapter/SqliteAdapter.php index 3acde97a..1cb65d1f 100644 --- a/src/Db/Adapter/SqliteAdapter.php +++ b/src/Db/Adapter/SqliteAdapter.php @@ -39,17 +39,14 @@ class SqliteAdapter extends AbstractAdapter self::PHINX_TYPE_BIG_INTEGER => 'biginteger', self::PHINX_TYPE_BINARY => 'binary_blob', self::PHINX_TYPE_BINARYUUID => 'uuid_blob', - self::PHINX_TYPE_BLOB => 'blob', self::PHINX_TYPE_BOOLEAN => 'boolean_integer', self::PHINX_TYPE_CHAR => 'char', self::PHINX_TYPE_DATE => 'date_text', self::PHINX_TYPE_DATETIME => 'datetime_text', self::PHINX_TYPE_DECIMAL => 'decimal', - self::PHINX_TYPE_DOUBLE => 'double', self::PHINX_TYPE_FLOAT => 'float', self::PHINX_TYPE_INTEGER => 'integer', self::PHINX_TYPE_JSON => 'json_text', - self::PHINX_TYPE_JSONB => 'jsonb_text', self::PHINX_TYPE_SMALL_INTEGER => 'smallinteger', self::PHINX_TYPE_STRING => 'varchar', self::PHINX_TYPE_TEXT => 'text', @@ -57,7 +54,6 @@ class SqliteAdapter extends AbstractAdapter self::PHINX_TYPE_TIMESTAMP => 'timestamp_text', self::PHINX_TYPE_TINY_INTEGER => 'tinyinteger', self::PHINX_TYPE_UUID => 'uuid_text', - self::PHINX_TYPE_VARBINARY => 'varbinary_blob', ]; /** diff --git a/src/Db/Adapter/SqlserverAdapter.php b/src/Db/Adapter/SqlserverAdapter.php index f8375a46..cb111e32 100644 --- a/src/Db/Adapter/SqlserverAdapter.php +++ b/src/Db/Adapter/SqlserverAdapter.php @@ -31,7 +31,6 @@ class SqlserverAdapter extends AbstractAdapter * @var string[] */ protected static array $specificColumnTypes = [ - self::PHINX_TYPE_FILESTREAM, self::PHINX_TYPE_BINARYUUID, self::PHINX_TYPE_NATIVEUUID, ]; diff --git a/src/Db/Table/Column.php b/src/Db/Table/Column.php index ef792af6..03d64775 100644 --- a/src/Db/Table/Column.php +++ b/src/Db/Table/Column.php @@ -39,20 +39,10 @@ class Column public const BINARYUUID = TableSchemaInterface::TYPE_BINARY_UUID; public const NATIVEUUID = TableSchemaInterface::TYPE_NATIVE_UUID; /** MySQL-only column type */ - public const MEDIUMINTEGER = AdapterInterface::PHINX_TYPE_MEDIUM_INTEGER; - /** MySQL-only column type */ - public const ENUM = AdapterInterface::PHINX_TYPE_ENUM; - /** MySQL-only column type */ - public const SET = AdapterInterface::PHINX_TYPE_STRING; - /** MySQL-only column type */ - public const BLOB = AdapterInterface::PHINX_TYPE_BLOB; - /** MySQL-only column type */ public const YEAR = AdapterInterface::PHINX_TYPE_YEAR; /** MySQL/Postgres-only column type */ public const JSON = TableSchemaInterface::TYPE_JSON; /** Postgres-only column type */ - public const JSONB = AdapterInterface::PHINX_TYPE_JSONB; - /** Postgres-only column type */ public const CIDR = AdapterInterface::PHINX_TYPE_CIDR; /** Postgres-only column type */ public const INET = AdapterInterface::PHINX_TYPE_INET; diff --git a/tests/TestCase/Db/Adapter/MysqlAdapterTest.php b/tests/TestCase/Db/Adapter/MysqlAdapterTest.php index f5739c80..52973186 100644 --- a/tests/TestCase/Db/Adapter/MysqlAdapterTest.php +++ b/tests/TestCase/Db/Adapter/MysqlAdapterTest.php @@ -10,7 +10,6 @@ use Cake\Database\Connection; use Cake\Datasource\ConnectionManager; use InvalidArgumentException; -use Migrations\Db\Adapter\AdapterInterface; use Migrations\Db\Adapter\MysqlAdapter; use Migrations\Db\Literal; use Migrations\Db\Table; @@ -21,7 +20,6 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\RunInSeparateProcess; use PHPUnit\Framework\TestCase; -use ReflectionClass; class MysqlAdapterTest extends TestCase { @@ -783,38 +781,6 @@ public function testIntegerColumnTypes($phinx_type, $options, $sql_type, $width, $this->assertEquals($type, $rows[1]['Type']); } - /** - * Test that migrations still supports the `double` type but - * as an alias for a float/double column which cake/database provides. - */ - public function testAddDoubleDefaultSignedCompat(): void - { - $table = new Table('table1', [], $this->adapter); - $table->save(); - $this->assertFalse($table->hasColumn('user_id')); - $table->addColumn('foo', 'double') - ->save(); - $rows = $this->adapter->fetchAll('SHOW FULL COLUMNS FROM table1'); - $this->assertEquals('double', $rows[1]['Type']); - $this->assertEquals('YES', $rows[1]['Null']); - } - - /** - * Test that migrations still supports the `double` type but - * as an alias for a float column which cake/database provides. - */ - public function testAddDoubleDefaultSignedCompatWithUnsigned(): void - { - $table = new Table('table1', [], $this->adapter); - $table->save(); - $this->assertFalse($table->hasColumn('user_id')); - $table->addColumn('foo', 'double', ['signed' => false]) - ->save(); - $rows = $this->adapter->fetchAll('SHOW COLUMNS FROM table1'); - $this->assertEquals('double unsigned', $rows[1]['Type']); - $this->assertEquals('YES', $rows[1]['Null']); - } - public function testAddStringColumnWithSignedEqualsFalse(): void { $table = new Table('table1', [], $this->adapter); @@ -2088,29 +2054,9 @@ public function testGeometrySridThrowsInsertDifferentSrid($type, $geom) $this->adapter->execute("INSERT INTO table1 (`geom`) VALUES (ST_GeomFromText('{$geom}', 4322))"); } - /** - * Small check to verify if specific Mysql constants are handled in AdapterInterface - * - * @see https://github.com/cakephp/migrations/issues/359 - */ - public function testMysqlBlobsConstants() - { - $reflector = new ReflectionClass(AdapterInterface::class); - - $validTypes = array_filter($reflector->getConstants(), function ($constant) { - return substr($constant, 0, strlen('PHINX_TYPE_')) === 'PHINX_TYPE_'; - }, ARRAY_FILTER_USE_KEY); - - $this->assertTrue(in_array('tinyblob', $validTypes, true)); - $this->assertTrue(in_array('blob', $validTypes, true)); - $this->assertTrue(in_array('mediumblob', $validTypes, true)); - $this->assertTrue(in_array('longblob', $validTypes, true)); - } - public static function defaultsCastAsExpressions() { return [ - [MysqlAdapter::PHINX_TYPE_BLOB, 'abc'], [MysqlAdapter::PHINX_TYPE_JSON, '{"a": true}'], [MysqlAdapter::PHINX_TYPE_TEXT, 'abc'], [MysqlAdapter::PHINX_TYPE_GEOMETRY, 'POINT(0 0)'], diff --git a/tests/TestCase/Db/Adapter/SqliteAdapterTest.php b/tests/TestCase/Db/Adapter/SqliteAdapterTest.php index 99aa98c3..4de70d0b 100644 --- a/tests/TestCase/Db/Adapter/SqliteAdapterTest.php +++ b/tests/TestCase/Db/Adapter/SqliteAdapterTest.php @@ -2660,28 +2660,21 @@ public static function provideColumnTypesForValidation() return [ [SqliteAdapter::PHINX_TYPE_BIG_INTEGER, true], [SqliteAdapter::PHINX_TYPE_BINARY, true], - [SqliteAdapter::PHINX_TYPE_BLOB, true], [SqliteAdapter::PHINX_TYPE_BOOLEAN, true], [SqliteAdapter::PHINX_TYPE_CHAR, true], [SqliteAdapter::PHINX_TYPE_DATE, true], [SqliteAdapter::PHINX_TYPE_DATETIME, true], - [SqliteAdapter::PHINX_TYPE_DOUBLE, true], [SqliteAdapter::PHINX_TYPE_FLOAT, true], [SqliteAdapter::PHINX_TYPE_INTEGER, true], [SqliteAdapter::PHINX_TYPE_JSON, true], - [SqliteAdapter::PHINX_TYPE_JSONB, true], [SqliteAdapter::PHINX_TYPE_SMALL_INTEGER, true], [SqliteAdapter::PHINX_TYPE_STRING, true], [SqliteAdapter::PHINX_TYPE_TEXT, true], [SqliteAdapter::PHINX_TYPE_TIME, true], [SqliteAdapter::PHINX_TYPE_UUID, true], [SqliteAdapter::PHINX_TYPE_TIMESTAMP, true], - [SqliteAdapter::PHINX_TYPE_VARBINARY, true], - [SqliteAdapter::PHINX_TYPE_BIT, false], [SqliteAdapter::PHINX_TYPE_CIDR, false], [SqliteAdapter::PHINX_TYPE_DECIMAL, true], - [SqliteAdapter::PHINX_TYPE_ENUM, false], - [SqliteAdapter::PHINX_TYPE_FILESTREAM, false], [SqliteAdapter::PHINX_TYPE_GEOMETRY, false], [SqliteAdapter::PHINX_TYPE_INET, false], [SqliteAdapter::PHINX_TYPE_INTERVAL, false], @@ -2689,7 +2682,6 @@ public static function provideColumnTypesForValidation() [SqliteAdapter::PHINX_TYPE_MACADDR, false], [SqliteAdapter::PHINX_TYPE_POINT, false], [SqliteAdapter::PHINX_TYPE_POLYGON, false], - [SqliteAdapter::PHINX_TYPE_SET, false], [Literal::from('someType'), true], ['someType', false], ];