Upgrading Dibi and Texy
Since version 4.1 of the Dibi database layer and version 3.0 of Texy, both libraries have renamed classes,
constants and parameters, and dropped part of their API without a replacement. The package dresscode/upgrade-deegee
holds these changes: with it, DressCode rewrites insertId() to getInsertId(),
Type::DATETIME to Type::DateTime, and calls to Texy helper methods that moved to
Texy\Helpers; for the API that is gone, it says what to do next.
Installation
To upgrade an application that still runs on PHP older than 8.4, install DressCode globally, because DressCode itself needs PHP 8.4 (see Where DressCode Runs):
composer global require dresscode/dresscode dresscode/upgrade-deegee phpstan/phpstan
dresscode upgrade today
The second line already rewrites the code: upgrade today finds the data of the package on its own, needs no
configuration, and leaves the style of the code as it is. Upgrading Code describes
the procedure and what to do with what is left. A project that already runs on PHP 8.4 to 8.6 can also add the package as a
development dependency, composer require --dev dresscode/upgrade-deegee phpstan/phpstan, and then run
vendor/bin/dresscode upgrade today.
What Gets Fixed
Here is a repository class written for Dibi 4 and Texy 3.1, in a project on the current versions:
public function insert(array $data): int
{
$this->db->query('INSERT INTO articles', $data);
return $this->db->insertId(); // Method `Dibi\Connection::insertId()` is replaced by `Connection::getInsertId()`.
}
public function render(string $text): string
{
$html = $this->texy->process($text);
return $this->texy->unProtect($html); // Method `Texy\Texy::unProtect()` is replaced by `Texy::unprotect()`.
}
public function getColumnType(): string
{
return Type::DATETIME; // Constant `Dibi\Type::DATETIME` is replaced by `Type::DateTime`.
}
After dresscode upgrade today:
public function insert(array $data): int
{
$this->db->query('INSERT INTO articles', $data);
return $this->db->getInsertId();
}
public function render(string $text): string
{
$html = $this->texy->process($text);
return $this->texy->unprotect($html);
}
public function getColumnType(): string
{
return Type::DateTime;
}
From Dibi, DressCode fixes the constants that used to be in uppercase, in Dibi\Type, Fluent, the
drivers and the static facade dibi (dibi::AFFECTED_ROWS to Dibi\Fluent::AffectedRows),
renamed methods such as insertId() to getInsertId(), DibiExtension22 to
DibiExtension3, and more. From Texy: classes with the prefix Texy to the namespace Texy\,
helper methods of Texy and Utf moved to Texy\Helpers, escapeHtml() to
htmlspecialchars(), and renamed properties, constants and parameters.
What Is Left to You
Where there is no replacement, DressCode reports the place and says what to do next. This covers, for example, the method
translateArgs(), which Dibi 4.2 removed, or output modes Texy no longer has:
Method `Dibi\Connection::translateArgs()` is forbidden: there is no replacement; the hook is gone; the SQL is generated by `translate()`, which is final and takes the arguments as variadic parameters.
Method `Texy\Texy::setOutputMode()` is forbidden: there is no replacement; the output is always HTML5.
From Dibi, DressCode also reports, for example, the extension methods extensionMethod() and the trait
Dibi\Strict; from Texy, the HTML4 and XHTML output modes, encodings other than UTF-8, and methods of modules that
became private in version 3.2.
What a library only quietly marks as deprecated is not in the data. With the types, DressCode reports it anyway, and where the annotation names the replacement, it rewrites the code. The data does not capture changes in behavior at all.
Keeping the Old API from Coming Back
The everyday check watches for the old API too, for example in continuous integration, once the configuration adds the types
and the set deprecations (see Upgrading Code). The package carries only
data, no plugin, so you do not have to name it in use:
typeAnalysis: phpstan
use:
- perCs # your standard
- deprecations
What the Package Covers
| library | versions |
|---|---|
dibi/dibi |
4.1 to 5.1 |
texy/texy |
3.0 to 3.2 |
Upgrading Code describes how to proceed one major version at a time.