Skip to content

Commit 7b1367b

Browse files
nicolas-grekaskelunikbwoebi
authored
Use str_increment() to fix PHP 8.5 deprecation (#457)
Also updates the GitHub action versions to fix the build. Co-authored-by: Niklas Keller <me@kelunik.com> Co-authored-by: Bob Weinand <bobwei9@hotmail.com>
1 parent ded3d9b commit 7b1367b

File tree

7 files changed

+29
-38
lines changed

7 files changed

+29
-38
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,19 @@ jobs:
5555
git config --global core.eol lf
5656
5757
- name: Checkout code
58-
uses: actions/checkout@v2
58+
uses: actions/checkout@v5
5959

6060
- name: Setup PHP
6161
uses: shivammathur/setup-php@v2
6262
with:
6363
php-version: ${{ matrix.php-version }}
6464

65-
- name: Get Composer cache directory
66-
id: composer-cache
67-
run: echo "::set-output name=dir::$(composer config cache-dir)"
68-
69-
- name: Cache dependencies
70-
uses: actions/cache@v2
71-
with:
72-
path: ${{ steps.composer-cache.outputs.dir }}
73-
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-${{ matrix.composer-flags }}
74-
restore-keys: |
75-
composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-
76-
composer-${{ runner.os }}-${{ matrix.php-version }}-
77-
composer-${{ runner.os }}-
78-
composer-
79-
8065
- name: Install dependencies
81-
uses: nick-invision/retry@v2
82-
with:
83-
timeout_minutes: 5
84-
max_attempts: 5
85-
retry_wait_seconds: 30
86-
command: |
87-
composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}
88-
composer info -D
66+
env:
67+
COMPOSER_ROOT_VERSION: 2.x-dev
68+
run: |
69+
composer update --optimize-autoloader --no-progress
70+
composer info -D
8971
9072
- name: Run tests
9173
env:

composer.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@
6262
"issues": "https://github.com/amphp/amp/issues",
6363
"irc": "irc://irc.freenode.org/amphp"
6464
},
65-
"extra": {
66-
"branch-alias": {
67-
"dev-master": "2.x-dev"
68-
}
69-
},
7065
"scripts": {
7166
"test": "@php -dzend.assertions=1 -dassert.exception=1 ./vendor/bin/phpunit",
7267
"code-style": "@php ./vendor/bin/php-cs-fixer fix"

lib/CancellationTokenSource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ private function invokeCallback(callable $callback)
108108

109109
public function subscribe(callable $callback): string
110110
{
111-
$id = $this->nextId++;
111+
$id = $this->nextId;
112+
\PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId;
112113

113114
if ($this->exception) {
114115
$this->invokeCallback($callback);

lib/CombinedCancellationToken.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public function __destruct()
4848
/** @inheritdoc */
4949
public function subscribe(callable $callback): string
5050
{
51-
$id = $this->nextId++;
51+
$id = $this->nextId;
52+
\PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId;
5253

5354
if ($this->exception) {
5455
asyncCall($callback, $this->exception);

lib/Loop/Driver.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,10 @@ public function defer(callable $callback, $data = null): string
189189
/** @psalm-var Watcher<null> $watcher */
190190
$watcher = new Watcher;
191191
$watcher->type = Watcher::DEFER;
192-
$watcher->id = $this->nextId++;
192+
$watcher->id = $this->nextId;
193193
$watcher->callback = $callback;
194194
$watcher->data = $data;
195+
\PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId;
195196

196197
$this->watchers[$watcher->id] = $watcher;
197198
$this->nextTickQueue[$watcher->id] = $watcher;
@@ -224,11 +225,12 @@ public function delay(int $delay, callable $callback, $data = null): string
224225
/** @psalm-var Watcher<int> $watcher */
225226
$watcher = new Watcher;
226227
$watcher->type = Watcher::DELAY;
227-
$watcher->id = $this->nextId++;
228+
$watcher->id = $this->nextId;
228229
$watcher->callback = $callback;
229230
$watcher->value = $delay;
230231
$watcher->expiration = $this->now() + $delay;
231232
$watcher->data = $data;
233+
\PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId;
232234

233235
$this->watchers[$watcher->id] = $watcher;
234236
$this->enableQueue[$watcher->id] = $watcher;
@@ -261,11 +263,12 @@ public function repeat(int $interval, callable $callback, $data = null): string
261263
/** @psalm-var Watcher<int> $watcher */
262264
$watcher = new Watcher;
263265
$watcher->type = Watcher::REPEAT;
264-
$watcher->id = $this->nextId++;
266+
$watcher->id = $this->nextId;
265267
$watcher->callback = $callback;
266268
$watcher->value = $interval;
267269
$watcher->expiration = $this->now() + $interval;
268270
$watcher->data = $data;
271+
\PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId;
269272

270273
$this->watchers[$watcher->id] = $watcher;
271274
$this->enableQueue[$watcher->id] = $watcher;
@@ -297,10 +300,11 @@ public function onReadable($stream, callable $callback, $data = null): string
297300
/** @psalm-var Watcher<resource> $watcher */
298301
$watcher = new Watcher;
299302
$watcher->type = Watcher::READABLE;
300-
$watcher->id = $this->nextId++;
303+
$watcher->id = $this->nextId;
301304
$watcher->callback = $callback;
302305
$watcher->value = $stream;
303306
$watcher->data = $data;
307+
\PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId;
304308

305309
$this->watchers[$watcher->id] = $watcher;
306310
$this->enableQueue[$watcher->id] = $watcher;
@@ -332,10 +336,11 @@ public function onWritable($stream, callable $callback, $data = null): string
332336
/** @psalm-var Watcher<resource> $watcher */
333337
$watcher = new Watcher;
334338
$watcher->type = Watcher::WRITABLE;
335-
$watcher->id = $this->nextId++;
339+
$watcher->id = $this->nextId;
336340
$watcher->callback = $callback;
337341
$watcher->value = $stream;
338342
$watcher->data = $data;
343+
\PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId;
339344

340345
$this->watchers[$watcher->id] = $watcher;
341346
$this->enableQueue[$watcher->id] = $watcher;
@@ -368,10 +373,11 @@ public function onSignal(int $signo, callable $callback, $data = null): string
368373
/** @psalm-var Watcher<int> $watcher */
369374
$watcher = new Watcher;
370375
$watcher->type = Watcher::SIGNAL;
371-
$watcher->id = $this->nextId++;
376+
$watcher->id = $this->nextId;
372377
$watcher->callback = $callback;
373378
$watcher->value = $signo;
374379
$watcher->data = $data;
380+
\PHP_VERSION_ID >= 80300 ? $this->nextId = \str_increment($this->nextId) : ++$this->nextId;
375381

376382
$this->watchers[$watcher->id] = $watcher;
377383
$this->enableQueue[$watcher->id] = $watcher;

psalm.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
</errorLevel>
3434
</StringIncrement>
3535

36+
<UndefinedFunction>
37+
<errorLevel type="suppress">
38+
<referencedFunction name="str_increment"/>
39+
</errorLevel>
40+
</UndefinedFunction>
41+
3642
<RedundantConditionGivenDocblockType>
3743
<errorLevel type="suppress">
3844
<directory name="lib"/>

test/InvalidYieldErrorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public function testSubgenerator()
3333
})();
3434

3535
$error = new InvalidYieldError($gen, "prefix");
36-
$this->assertSame("prefix; integer yielded at key 'foo' on line " . (__LINE__ - 8) . " in " . __FILE__, $error->getMessage());
36+
$this->assertSame("prefix; integer yielded at key 'foo' on line " . (__LINE__ - 8 - (int) (\PHP_VERSION_ID >= 80400)) . " in " . __FILE__, $error->getMessage());
3737
}
3838
}

0 commit comments

Comments
 (0)