From 74200c3b36c569043e099e5b8a0ff6ce322603c6 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 27 Aug 2025 23:42:00 +0200 Subject: [PATCH] Use str_increment() to fix PHP 8.5 deprecation Also updates the GitHub action versions to fix the build. Co-authored-by: Niklas Keller Co-authored-by: Bob Weinand --- .github/workflows/ci.yml | 30 ++++++------------------------ composer.json | 5 ----- lib/CancellationTokenSource.php | 3 ++- lib/CombinedCancellationToken.php | 3 ++- lib/Loop/Driver.php | 18 ++++++++++++------ psalm.xml | 6 ++++++ test/InvalidYieldErrorTest.php | 2 +- 7 files changed, 29 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ed5d7d39..05ba2794 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,37 +55,19 @@ jobs: git config --global core.eol lf - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v5 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} - - name: Get Composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-dir)" - - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-${{ matrix.composer-flags }} - restore-keys: | - composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}- - composer-${{ runner.os }}-${{ matrix.php-version }}- - composer-${{ runner.os }}- - composer- - - name: Install dependencies - uses: nick-invision/retry@v2 - with: - timeout_minutes: 5 - max_attempts: 5 - retry_wait_seconds: 30 - command: | - composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }} - composer info -D + env: + COMPOSER_ROOT_VERSION: 2.x-dev + run: | + composer update --optimize-autoloader --no-progress + composer info -D - name: Run tests env: diff --git a/composer.json b/composer.json index 5fa717cf..6fa86492 100644 --- a/composer.json +++ b/composer.json @@ -62,11 +62,6 @@ "issues": "https://github.com/amphp/amp/issues", "irc": "irc://irc.freenode.org/amphp" }, - "extra": { - "branch-alias": { - "dev-master": "2.x-dev" - } - }, "scripts": { "test": "@php -dzend.assertions=1 -dassert.exception=1 ./vendor/bin/phpunit", "code-style": "@php ./vendor/bin/php-cs-fixer fix" diff --git a/lib/CancellationTokenSource.php b/lib/CancellationTokenSource.php index 965c7cb0..0f777bdf 100644 --- a/lib/CancellationTokenSource.php +++ b/lib/CancellationTokenSource.php @@ -108,7 +108,8 @@ private function invokeCallback(callable $callback) public function subscribe(callable $callback): string { - $id = $this->nextId++; + $id = $this->nextId; + \PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId; if ($this->exception) { $this->invokeCallback($callback); diff --git a/lib/CombinedCancellationToken.php b/lib/CombinedCancellationToken.php index 6b250d2b..6b48e3ec 100644 --- a/lib/CombinedCancellationToken.php +++ b/lib/CombinedCancellationToken.php @@ -48,7 +48,8 @@ public function __destruct() /** @inheritdoc */ public function subscribe(callable $callback): string { - $id = $this->nextId++; + $id = $this->nextId; + \PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId; if ($this->exception) { asyncCall($callback, $this->exception); diff --git a/lib/Loop/Driver.php b/lib/Loop/Driver.php index 89b372a7..dc2a6024 100644 --- a/lib/Loop/Driver.php +++ b/lib/Loop/Driver.php @@ -189,9 +189,10 @@ public function defer(callable $callback, $data = null): string /** @psalm-var Watcher $watcher */ $watcher = new Watcher; $watcher->type = Watcher::DEFER; - $watcher->id = $this->nextId++; + $watcher->id = $this->nextId; $watcher->callback = $callback; $watcher->data = $data; + \PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId; $this->watchers[$watcher->id] = $watcher; $this->nextTickQueue[$watcher->id] = $watcher; @@ -224,11 +225,12 @@ public function delay(int $delay, callable $callback, $data = null): string /** @psalm-var Watcher $watcher */ $watcher = new Watcher; $watcher->type = Watcher::DELAY; - $watcher->id = $this->nextId++; + $watcher->id = $this->nextId; $watcher->callback = $callback; $watcher->value = $delay; $watcher->expiration = $this->now() + $delay; $watcher->data = $data; + \PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId; $this->watchers[$watcher->id] = $watcher; $this->enableQueue[$watcher->id] = $watcher; @@ -261,11 +263,12 @@ public function repeat(int $interval, callable $callback, $data = null): string /** @psalm-var Watcher $watcher */ $watcher = new Watcher; $watcher->type = Watcher::REPEAT; - $watcher->id = $this->nextId++; + $watcher->id = $this->nextId; $watcher->callback = $callback; $watcher->value = $interval; $watcher->expiration = $this->now() + $interval; $watcher->data = $data; + \PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId; $this->watchers[$watcher->id] = $watcher; $this->enableQueue[$watcher->id] = $watcher; @@ -297,10 +300,11 @@ public function onReadable($stream, callable $callback, $data = null): string /** @psalm-var Watcher $watcher */ $watcher = new Watcher; $watcher->type = Watcher::READABLE; - $watcher->id = $this->nextId++; + $watcher->id = $this->nextId; $watcher->callback = $callback; $watcher->value = $stream; $watcher->data = $data; + \PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId; $this->watchers[$watcher->id] = $watcher; $this->enableQueue[$watcher->id] = $watcher; @@ -332,10 +336,11 @@ public function onWritable($stream, callable $callback, $data = null): string /** @psalm-var Watcher $watcher */ $watcher = new Watcher; $watcher->type = Watcher::WRITABLE; - $watcher->id = $this->nextId++; + $watcher->id = $this->nextId; $watcher->callback = $callback; $watcher->value = $stream; $watcher->data = $data; + \PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId; $this->watchers[$watcher->id] = $watcher; $this->enableQueue[$watcher->id] = $watcher; @@ -368,10 +373,11 @@ public function onSignal(int $signo, callable $callback, $data = null): string /** @psalm-var Watcher $watcher */ $watcher = new Watcher; $watcher->type = Watcher::SIGNAL; - $watcher->id = $this->nextId++; + $watcher->id = $this->nextId; $watcher->callback = $callback; $watcher->value = $signo; $watcher->data = $data; + \PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId; $this->watchers[$watcher->id] = $watcher; $this->enableQueue[$watcher->id] = $watcher; diff --git a/psalm.xml b/psalm.xml index ad5dd774..27654097 100644 --- a/psalm.xml +++ b/psalm.xml @@ -33,6 +33,12 @@ + + + + + + diff --git a/test/InvalidYieldErrorTest.php b/test/InvalidYieldErrorTest.php index f92a4a1f..d845fefb 100644 --- a/test/InvalidYieldErrorTest.php +++ b/test/InvalidYieldErrorTest.php @@ -33,6 +33,6 @@ public function testSubgenerator() })(); $error = new InvalidYieldError($gen, "prefix"); - $this->assertSame("prefix; integer yielded at key 'foo' on line " . (__LINE__ - 8) . " in " . __FILE__, $error->getMessage()); + $this->assertSame("prefix; integer yielded at key 'foo' on line " . (__LINE__ - 8 - (int) (\PHP_VERSION_ID >= 80400)) . " in " . __FILE__, $error->getMessage()); } }