Skip to content

Commit a293e68

Browse files
committed
docs(downgrade): clarify the handling of arrow functions and project files in PHP downgrade process
1 parent 130a726 commit a293e68

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎blog/downgrade.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ It was also a good moment to move the container into its own package, [internal/
4848

4949
First I ran the downgrade locally: rewrote the entire codebase to 8.1 and ran the tests on it under 8.1. Rector handled almost everything, and that "almost" was the interesting part:
5050

51-
- The `never` rule didn't know about arrow functions; it only downgraded regular `function(): never`. I sent a [fix](https://github.com/rectorphp/rector-downgrade-php/pull/397), and it was accepted.
51+
- The `never` rule didn't know about arrow functions; it only downgraded regular `function(): never`. I sent a [fix](https://github.com/rectorphp/rector-downgrade-php/pull/397), then a [second one](https://github.com/rectorphp/rector-downgrade-php/pull/399) for the 8.2-to-8.1 rule set.
5252
- There was no rule for `ReflectionMethod::hasPrototype()` at all. I wrote a [new one](https://github.com/rectorphp/rector-downgrade-php/pull/398): the call is replaced with `try { getPrototype() } catch`. `getPrototype()` has been around forever and throws when there is no prototype.
5353
- `memory_reset_peak_usage()` is a [dead end](https://github.com/rectorphp/rector/issues/9890). A polyfill is impossible: the function has no userland equivalent, only the engine can reset the memory peak. In the end, the call in the benchmarks is wrapped in `function_exists()`, and the one test that compares the peak memory of two algorithms is simply skipped on 8.1: without the reset, its measurement is meaningless.
5454

@@ -87,7 +87,7 @@ Once everything resolves, a single Rector pass over the copied packages brings t
8787

8888
This is how the [universal action](https://github.com/php-internal/actions) came to be: `php-internal/actions/downgrade`. You give it a target PHP version, and it installs dependencies at the newest versions that fit that platform, downgrading only what wouldn't install otherwise.
8989

90-
It isn't limited to the vendor directory: the project's own files can be downgraded as well. The `testo.php` config and the tests themselves are written for PHP 8.2, for instance, so it makes sense to bring them down to 8.1 too. Let the tests stay pretty, and let Rector sort it out.
90+
It isn't limited to the vendor directory: the project's own files can be downgraded as well. The `testo.php` config and the tests themselves are written for PHP 8.2, for instance, so it makes sense to bring them down to 8.1 too. Let the tests stay pretty, and Rector will sort out the rest.
9191

9292

9393
```yaml

‎ru/blog/downgrade.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ author: Алексей Гагарин
4848

4949
Сначала я прогнал даунгрейд локально: переписал всю кодовую базу в 8.1 и запустил на ней тесты под 8.1. Rector справился почти со всем, но именно «почти» и было интересно:
5050

51-
- Правило для `never` не знало про стрелочные функции — оно понижало только обычные `function(): never`. Отправил [фикс](https://github.com/rectorphp/rector-downgrade-php/pull/397), приняли.
51+
- Правило для `never` не знало про стрелочные функции — оно понижало только обычные `function(): never`. Отправил [фикс](https://github.com/rectorphp/rector-downgrade-php/pull/397), а потом [второй](https://github.com/rectorphp/rector-downgrade-php/pull/399) уже в наборе «с 8.2 на 8.1».
5252
- Правила для `ReflectionMethod::hasPrototype()` не было вовсе. Написал [новое](https://github.com/rectorphp/rector-downgrade-php/pull/398): вызов заменяется на `try { getPrototype() } catch` — `getPrototype()` есть с незапамятных времён и на отсутствие прототипа бросает исключение.
5353
- `memory_reset_peak_usage()` — [тупик](https://github.com/rectorphp/rector/issues/9890). Полифилл написать нельзя: у функции нет аналога в юзерленде, пик памяти сбрасывается только движком. В итоге в бенчмарках вызов обёрнут в `function_exists()`, а один тест, который сравнивает пиковое потребление двух алгоритмов, на 8.1 честно скипается — без сброса пика его измерение ничего не значит.
5454

@@ -87,7 +87,7 @@ author: Алексей Гагарин
8787

8888
Так и получился [универсальный экшен](https://github.com/php-internal/actions): `php-internal/actions/downgrade`. Ему говоришь целевую версию PHP, а он ставит зависимости с максимально новыми версиями, какие только встают на эту платформу, и понижает лишь то, что иначе не встанет.
8989

90-
Понижать можно не только вендор, но также файлы самого проекта. Например, конфиг `testo.php` и сами тесты написаны под PHP 8.2 — имеет смысл понизить до 8.1. Пусть тесты остаются красивыми, а Rector разберётся.
90+
Понижать можно не только вендор, но также файлы самого проекта. Например, конфиг `testo.php` и сами тесты написаны под PHP 8.2 — имеет смысл понизить до 8.1. Пусть тесты остаются красивыми, а с остальным разберётся Rector.
9191

9292

9393
```yaml

0 commit comments

Comments
 (0)