-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from clue-labs/template-types-v3
[3.x] Add template annotations
- Loading branch information
Showing
12 changed files
with
239 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,6 @@ jobs: | |
- 7.4 | ||
- 7.3 | ||
- 7.2 | ||
- 7.1 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: shivammathur/setup-php@v2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
use function PHPStan\Testing\assertType; | ||
use function React\Async\await; | ||
use function React\Promise\resolve; | ||
|
||
assertType('bool', await(resolve(true))); | ||
|
||
final class AwaitExampleUser | ||
{ | ||
public string $name; | ||
|
||
public function __construct(string $name) { | ||
$this->name = $name; | ||
} | ||
} | ||
|
||
assertType('string', await(resolve(new AwaitExampleUser('WyriHaximus')))->name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
use function PHPStan\Testing\assertType; | ||
use function React\Async\await; | ||
use function React\Async\coroutine; | ||
use function React\Promise\resolve; | ||
|
||
assertType('React\Promise\PromiseInterface<bool>', coroutine(static function () { | ||
return true; | ||
})); | ||
|
||
assertType('React\Promise\PromiseInterface<bool>', coroutine(static function () { | ||
return resolve(true); | ||
})); | ||
|
||
// assertType('React\Promise\PromiseInterface<bool>', coroutine(static function () { | ||
// return (yield resolve(true)); | ||
// })); | ||
|
||
assertType('React\Promise\PromiseInterface<int>', coroutine(static function () { | ||
// $bool = yield resolve(true); | ||
// assertType('bool', $bool); | ||
|
||
return time(); | ||
})); | ||
|
||
// assertType('React\Promise\PromiseInterface<bool>', coroutine(static function () { | ||
// $bool = yield resolve(true); | ||
// assertType('bool', $bool); | ||
|
||
// return $bool; | ||
// })); | ||
|
||
assertType('React\Promise\PromiseInterface<bool>', coroutine(static function () { | ||
yield resolve(time()); | ||
|
||
return true; | ||
})); | ||
|
||
assertType('React\Promise\PromiseInterface<bool>', coroutine(static function () { | ||
for ($i = 0; $i <= 10; $i++) { | ||
yield resolve($i); | ||
} | ||
|
||
return true; | ||
})); | ||
|
||
assertType('React\Promise\PromiseInterface<int>', coroutine(static function (int $a): int { return $a; }, 42)); | ||
assertType('React\Promise\PromiseInterface<int>', coroutine(static function (int $a, int $b): int { return $a + $b; }, 10, 32)); | ||
assertType('React\Promise\PromiseInterface<int>', coroutine(static function (int $a, int $b, int $c): int { return $a + $b + $c; }, 10, 22, 10)); | ||
assertType('React\Promise\PromiseInterface<int>', coroutine(static function (int $a, int $b, int $c, int $d): int { return $a + $b + $c + $d; }, 10, 22, 5, 5)); | ||
assertType('React\Promise\PromiseInterface<int>', coroutine(static function (int $a, int $b, int $c, int $d, int $e): int { return $a + $b + $c + $d + $e; }, 10, 12, 10, 5, 5)); | ||
|
||
assertType('bool', await(coroutine(static function () { | ||
return true; | ||
}))); | ||
|
||
// assertType('bool', await(coroutine(static function () { | ||
// return (yield resolve(true)); | ||
// }))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use React\Promise\PromiseInterface; | ||
use function PHPStan\Testing\assertType; | ||
use function React\Async\await; | ||
use function React\Async\parallel; | ||
use function React\Promise\resolve; | ||
|
||
assertType('React\Promise\PromiseInterface<array>', parallel([])); | ||
|
||
assertType('React\Promise\PromiseInterface<array<bool|float|int>>', parallel([ | ||
static function (): PromiseInterface { return resolve(true); }, | ||
static function (): PromiseInterface { return resolve(time()); }, | ||
static function (): PromiseInterface { return resolve(microtime(true)); }, | ||
])); | ||
|
||
assertType('React\Promise\PromiseInterface<array<bool|float|int>>', parallel([ | ||
static function (): bool { return true; }, | ||
static function (): int { return time(); }, | ||
static function (): float { return microtime(true); }, | ||
])); | ||
|
||
assertType('array<bool|float|int>', await(parallel([ | ||
static function (): PromiseInterface { return resolve(true); }, | ||
static function (): PromiseInterface { return resolve(time()); }, | ||
static function (): PromiseInterface { return resolve(microtime(true)); }, | ||
]))); | ||
|
||
assertType('array<bool|float|int>', await(parallel([ | ||
static function (): bool { return true; }, | ||
static function (): int { return time(); }, | ||
static function (): float { return microtime(true); }, | ||
]))); |
Oops, something went wrong.