Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 6 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion lib/CancellationTokenSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lib/CombinedCancellationToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 12 additions & 6 deletions lib/Loop/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ public function defer(callable $callback, $data = null): string
/** @psalm-var Watcher<null> $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;
Expand Down Expand Up @@ -224,11 +225,12 @@ public function delay(int $delay, callable $callback, $data = null): string
/** @psalm-var Watcher<int> $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;
Expand Down Expand Up @@ -261,11 +263,12 @@ public function repeat(int $interval, callable $callback, $data = null): string
/** @psalm-var Watcher<int> $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;
Expand Down Expand Up @@ -297,10 +300,11 @@ public function onReadable($stream, callable $callback, $data = null): string
/** @psalm-var Watcher<resource> $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;
Expand Down Expand Up @@ -332,10 +336,11 @@ public function onWritable($stream, callable $callback, $data = null): string
/** @psalm-var Watcher<resource> $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;
Expand Down Expand Up @@ -368,10 +373,11 @@ public function onSignal(int $signo, callable $callback, $data = null): string
/** @psalm-var Watcher<int> $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;
Expand Down
6 changes: 6 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
</errorLevel>
</StringIncrement>

<UndefinedFunction>
<errorLevel type="suppress">
<referencedFunction name="str_increment"/>
</errorLevel>
</UndefinedFunction>

<RedundantConditionGivenDocblockType>
<errorLevel type="suppress">
<directory name="lib"/>
Expand Down
2 changes: 1 addition & 1 deletion test/InvalidYieldErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Loading