From 9f18ad17d84203bd0c848a3f2569aea4a28a7bbb Mon Sep 17 00:00:00 2001 From: mscherer Date: Thu, 22 Jan 2026 08:29:53 +0100 Subject: [PATCH 1/2] Add TypeFactory::getMap($type) => getMapped($type) rector rule In CakePHP 5.3, calling TypeFactory::getMap() with a type argument is deprecated. Use getMapped() instead for single-type lookups. Fixes #354 --- config/rector/sets/cakephp53.php | 2 + .../MethodCall/TypeFactoryGetMappedRector.php | 82 +++++++++++++++++++ .../Fixture/fixture.php.inc | 45 ++++++++++ .../Fixture/skip_no_argument.php.inc | 18 ++++ .../TypeFactoryGetMappedRectorTest.php | 28 +++++++ .../config/configured_rule.php | 9 ++ .../src/SomeTest.php | 5 ++ .../src/SomeTest.php | 5 ++ 8 files changed, 194 insertions(+) create mode 100644 src/Rector/Rector/MethodCall/TypeFactoryGetMappedRector.php create mode 100644 tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/Fixture/fixture.php.inc create mode 100644 tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/Fixture/skip_no_argument.php.inc create mode 100644 tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/TypeFactoryGetMappedRectorTest.php create mode 100644 tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/config/configured_rule.php diff --git a/config/rector/sets/cakephp53.php b/config/rector/sets/cakephp53.php index 83c1c5d5..407d1815 100644 --- a/config/rector/sets/cakephp53.php +++ b/config/rector/sets/cakephp53.php @@ -6,6 +6,7 @@ use Cake\Upgrade\Rector\Rector\MethodCall\EntityPatchRector; use Cake\Upgrade\Rector\Rector\MethodCall\NewExprToFuncRector; use Cake\Upgrade\Rector\Rector\MethodCall\QueryParamAccessRector; +use Cake\Upgrade\Rector\Rector\MethodCall\TypeFactoryGetMappedRector; use Rector\Config\RectorConfig; use Rector\Renaming\Rector\MethodCall\RenameMethodRector; use Rector\Renaming\Rector\Name\RenameClassRector; @@ -28,4 +29,5 @@ $rectorConfig->rule(EntityPatchRector::class); $rectorConfig->rule(FormExecuteToProcessRector::class); $rectorConfig->rule(QueryParamAccessRector::class); + $rectorConfig->rule(TypeFactoryGetMappedRector::class); }; diff --git a/src/Rector/Rector/MethodCall/TypeFactoryGetMappedRector.php b/src/Rector/Rector/MethodCall/TypeFactoryGetMappedRector.php new file mode 100644 index 00000000..f3f19d4a --- /dev/null +++ b/src/Rector/Rector/MethodCall/TypeFactoryGetMappedRector.php @@ -0,0 +1,82 @@ +name instanceof Identifier || $node->name->toString() !== 'getMap') { + return null; + } + + // Must have at least one argument (the type) + if (count($node->args) < 1) { + return null; + } + + // Check if this is called on TypeFactory + if (!$node->class instanceof Name) { + return null; + } + + $className = $node->class->toString(); + if ($className !== 'Cake\Database\TypeFactory' && $className !== 'TypeFactory') { + return null; + } + + // Rename to getMapped + $node->name = new Identifier('getMapped'); + + return $node; + } +} diff --git a/tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/Fixture/fixture.php.inc b/tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/Fixture/fixture.php.inc new file mode 100644 index 00000000..581f2edf --- /dev/null +++ b/tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/Fixture/fixture.php.inc @@ -0,0 +1,45 @@ + +----- + diff --git a/tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/Fixture/skip_no_argument.php.inc b/tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/Fixture/skip_no_argument.php.inc new file mode 100644 index 00000000..113db4ff --- /dev/null +++ b/tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/Fixture/skip_no_argument.php.inc @@ -0,0 +1,18 @@ + diff --git a/tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/TypeFactoryGetMappedRectorTest.php b/tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/TypeFactoryGetMappedRectorTest.php new file mode 100644 index 00000000..371a0db5 --- /dev/null +++ b/tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/TypeFactoryGetMappedRectorTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/config/configured_rule.php b/tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/config/configured_rule.php new file mode 100644 index 00000000..a0747f6d --- /dev/null +++ b/tests/TestCase/Rector/MethodCall/TypeFactoryGetMappedRector/config/configured_rule.php @@ -0,0 +1,9 @@ +rule(TypeFactoryGetMappedRector::class); +}; diff --git a/tests/test_apps/original/RectorCommand-testApply53/src/SomeTest.php b/tests/test_apps/original/RectorCommand-testApply53/src/SomeTest.php index e3d9c78b..6c8e855c 100644 --- a/tests/test_apps/original/RectorCommand-testApply53/src/SomeTest.php +++ b/tests/test_apps/original/RectorCommand-testApply53/src/SomeTest.php @@ -3,6 +3,7 @@ namespace MyPlugin; +use Cake\Database\TypeFactory; use Cake\ORM\Entity; use Cake\ORM\Locator\LocatorAwareTrait; use Cake\ORM\Query; @@ -22,6 +23,10 @@ public function testRenames(): void $table = $this->fetchTable('Articles'); $expr = $table->find()->newExpr(); + + // TypeFactory::getMap($type) should be changed to getMapped($type) + $class = TypeFactory::getMap('datetime'); + $allTypes = TypeFactory::getMap(); // This should stay as is } public function findSomething(Query $query, array $options): Query { diff --git a/tests/test_apps/upgraded/RectorCommand-testApply53/src/SomeTest.php b/tests/test_apps/upgraded/RectorCommand-testApply53/src/SomeTest.php index 304c6187..d29afdf9 100644 --- a/tests/test_apps/upgraded/RectorCommand-testApply53/src/SomeTest.php +++ b/tests/test_apps/upgraded/RectorCommand-testApply53/src/SomeTest.php @@ -3,6 +3,7 @@ namespace MyPlugin; +use Cake\Database\TypeFactory; use Cake\ORM\Entity; use Cake\ORM\Locator\LocatorAwareTrait; use Cake\ORM\Query; @@ -22,6 +23,10 @@ public function testRenames(): void $table = $this->fetchTable('Articles'); $expr = $table->find()->expr(); + + // TypeFactory::getMap($type) should be changed to getMapped($type) + $class = TypeFactory::getMapped('datetime'); + $allTypes = TypeFactory::getMap(); // This should stay as is } public function findSomething(\Cake\ORM\Query\SelectQuery $query, array $options): \Cake\ORM\Query\SelectQuery { From 6e062b8a39a10d252a7e4d6d06e5d19370b17951 Mon Sep 17 00:00:00 2001 From: mscherer Date: Thu, 22 Jan 2026 08:42:24 +0100 Subject: [PATCH 2/2] Update CI to use PHP 8.2 (required by CakePHP 5.x) --- .github/workflows/ci.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2e11e7f..a28041ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,10 +17,10 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['8.1'] + php-version: ['8.2'] prefer-lowest: [''] include: - - php-version: '8.1' + - php-version: '8.2' prefer-lowest: 'prefer-lowest' steps: @@ -51,14 +51,12 @@ jobs: run: | if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then make install-dev-lowest - elif ${{ matrix.php-version == '8.1' }}; then - make install-dev-ignore-reqs else make install-dev fi - name: Setup problem matchers for PHPUnit - if: matrix.php-version == '8.1' + if: matrix.php-version == '8.2' run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run PHPUnit @@ -74,7 +72,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' extensions: mbstring, intl tools: cs2pr coverage: none