Skip to content

About

Utilities and libraries to assist in updating code from Laminas\Db to PhpDb

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

phpdb-laminas-migration

Rector rules for migrating an application from laminas-db 2.x to php-db/phpdb.

Warning

This tool is provided as-is, with no guarantee about the code it produces. Back up your code, or commit it to version control, before you begin, and review every change it makes before you deploy.

What it does

Each rule either rewrites code or leaves it alone and adds a comment:

  • Rewrite: the new code means the same as the old code.
  • Rewrite, review: the new code is right in the common case but behaves slightly differently, for example by catching more exceptions. The rule adds a TODO(phpdb-migration) comment that starts with review.
  • Flag: the right change depends on what the code meant. The rule leaves the code alone and adds a /** TODO(phpdb-migration) … */ docblock that explains the break and the replacement.

Each comment names the finding it relates to, for example TODO(phpdb-migration) R10:, which matches a heading in the documentation.

Requirements

  • PHP 8.3 or later
  • Rector 2.9 or later, installed with this package

Usage

  1. Back up or commit your code.

  2. Install phpdb and the driver package for your database, for example:

    composer require php-db/phpdb php-db/phpdb-mysql
  3. Install this package as a development dependency:

    composer require --dev php-db/phpdb-laminas-migration
  4. Add the set to rector.php:

    use PhpDb\LaminasMigration\Set\LaminasMigrationSetList;
    use Rector\Config\RectorConfig;
    
    return RectorConfig::configure()
        ->withPaths([__DIR__ . '/config', __DIR__ . '/src'])
        ->withSets([LaminasMigrationSetList::LAMINAS_DB_TO_PHPDB])
        ->withImportNames(removeUnusedImports: true);
  5. Preview the changes, then apply them:

    vendor/bin/rector process --dry-run
    vendor/bin/rector process
  6. Find everything left for you to check:

    grep -rn "TODO(phpdb-migration)" config src
  7. Remove laminas-db and this package once the migration is finished.

Sets

Set Covers
LAMINAS_DB_TO_PHPDB Every rule below, in the right order
MYSQL MySQL driver, platform and metadata classes
SQL Sql, Select, predicates and expressions
CONFIG Adapter construction and configuration, drivers and service factories
GATEWAY The adapter, gateways, result sets and metadata
EXTENSION Classes that extend or implement phpdb types
NAMESPACE Every other laminas-db class that phpdb keeps under the same name. Run it last

Use the area sets to migrate in stages. Run them in the order shown.

Contributing

config/class-map.php is generated. When phpdb adds or removes classes, regenerate it from a laminas-db 2.22 checkout and a phpdb checkout:

php bin/generate-class-map.php path/to/laminas-db/src path/to/phpdb/src

config/signatures.php is generated too, from the installed php-db/phpdb and php-db/phpdb-mysql packages. Regenerate it after updating them:

php bin/generate-signatures.php

The end-to-end tests run the full set on two small sample applications, a laminas-mvc one and a Mezzio one, in test/e2e, and compare the result with each app's expected/ tree. Run them with composer e2e. After a deliberate change to a rule, regenerate the expected trees and review the diff:

UPDATE_E2E=1 composer e2e

Status

This package is in early development. Only some rules are implemented so far; see the documentation for the rule list.

Documentation

See docs/book.

About

Utilities and libraries to assist in updating code from Laminas\Db to PhpDb

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages