Skip to content

Commit 99a3411

Browse files
committed
Turn into PHPStan extension
1 parent 9e6dbc5 commit 99a3411

File tree

5 files changed

+47
-53
lines changed

5 files changed

+47
-53
lines changed

composer.json

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "react-parallel/stubs",
3+
"type": "phpstan-extension",
34
"description": "\ud83e\udecf Stubs (for PHPstan)",
45
"license": "MIT",
56
"authors": [
@@ -28,6 +29,13 @@
2829
},
2930
"sort-packages": true
3031
},
32+
"extra": {
33+
"phpstan": {
34+
"includes": [
35+
"extension.neon"
36+
]
37+
}
38+
},
3139
"scripts": {
3240
"post-install-cmd": [
3341
"composer normalize"

extension.neon

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
stubFiles:
3+
- stubs/Channel.stub
4+
- stubs/Event.stub
5+
- stubs/Future.stub

stubs/Channel.stub

+15-30
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace parallel;
64

7-
/** @template T */
5+
/**
6+
* @template T
7+
*/
88
final class Channel
99
{
1010
/**
@@ -18,80 +18,65 @@ final class Channel
1818
* Shall make an anonymous unbuffered channel
1919
* Shall make an anonymous buffered channel with the given capacity
2020
*
21-
* @param int|null $capacity May be Channel::Infinite or a positive integer
21+
* @param null|int $capacity May be Channel::Infinite or a positive integer
2222
*/
23-
public function __construct(int|null $capacity = null)
24-
{
25-
}
23+
public function __construct(?int $capacity = null) {}
2624

2725
/* Access */
2826

2927
/**
3028
* Shall make an unbuffered channel with the given name
3129
* Shall make a buffered channel with the given name and capacity
3230
*
33-
* @param string $name The name of the channel.
34-
* @param int|null $capacity May be Channel::Infinite or a positive integer
31+
* @param string $name The name of the channel.
32+
* @param null|int $capacity May be Channel::Infinite or a positive integer
3533
*
3634
* @return Channel<T>
3735
*
3836
* @throws Channel\Error\Existence if channel already exists.
3937
*/
40-
public static function make(string $name, int|null $capacity = null): Channel
41-
{
42-
}
38+
public static function make(string $name, ?int $capacity = null): Channel {}
4339

4440
/**
4541
* Shall open the channel with the given name
4642
*
43+
* @param string $name
4744
* @return Channel<T>
4845
*
4946
* @throws Channel\Error\Existence if channel does not exist.
5047
*/
51-
public static function open(string $name): Channel
52-
{
53-
}
48+
public static function open(string $name): Channel {}
5449

5550
/* Sharing */
5651

5752
/**
5853
* Shall send the given value on this channel
59-
*
6054
* @param T $value
6155
*
6256
* @throws Channel\Error\Closed if channel is closed.
6357
* @throws Channel\Error\IllegalValue if value is illegal.
6458
*/
65-
public function send($value): void
66-
{
67-
}
59+
public function send($value): void {}
6860

6961
/**
7062
* Shall recv a value from this channel
71-
*
7263
* @return T
7364
*
7465
* @throws Channel\Error\Closed if channel is closed.
7566
*/
76-
public function recv()
77-
{
78-
}
67+
public function recv() {}
7968

8069
/* Closing */
8170

8271
/**
8372
* Shall close this channel
84-
*
8573
* @throws Channel\Error\Closed if channel is closed.
8674
*/
87-
public function close(): void
88-
{
89-
}
75+
public function close(): void {}
9076

9177
/**
9278
* Returns name of channel
79+
* @return string
9380
*/
94-
public function __toString(): string
95-
{
96-
}
81+
public function __toString(): string {}
9782
}

stubs/Event.stub

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace parallel\Events;
64

75
use parallel\Channel;
86
use parallel\Future;
97

10-
/** @template T */
8+
/**
9+
* @template T
10+
*/
1111
final class Event
1212
{
1313
/**
1414
* Shall be one of Event\Type constants
15+
* @var int
1516
*/
16-
public int $type;
17+
public $type;
1718

1819
/**
1920
* Shall be the source of the event (target name)
21+
* @var string
2022
*/
21-
public string $source;
23+
public $source;
2224

2325
/**
2426
* Shall be either Future or Channel
25-
*
2627
* @var Future<T>|Channel<T>
2728
*/
28-
public Future|Channel $object;
29+
public $object;
2930

3031
/**
3132
* Shall be set for Read/Error events
32-
*
3333
* @var T
3434
*/
3535
public $value;

stubs/Future.stub

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
namespace parallel;
64

75
use Throwable;
86

9-
/** @template T */
7+
/**
8+
* @template T
9+
*/
1010
final class Future
1111
{
1212
/* Resolution */
@@ -22,25 +22,21 @@ final class Future
2222
* @throws Future\Error\Foreign if task raised an unrecognized uncaught exception.
2323
* @throws Throwable Shall rethrow \Throwable uncaught in task
2424
*/
25-
public function value()
26-
{
27-
}
25+
public function value() {}
2826

2927
/* State */
3028

3129
/**
3230
* Shall indicate if the task is completed
31+
* @return bool
3332
*/
34-
public function done(): bool
35-
{
36-
}
33+
public function done(): bool {}
3734

3835
/**
3936
* Shall indicate if the task was cancelled
37+
* @return bool
4038
*/
41-
public function cancelled(): bool
42-
{
43-
}
39+
public function cancelled(): bool {}
4440

4541
/* Cancellation */
4642

@@ -49,10 +45,10 @@ final class Future
4945
* Note: If task is running, it will be interrupted.
5046
* Warning: Internal function calls in progress cannot be interrupted.
5147
*
48+
* @return bool
49+
*
5250
* @throws Future\Error\Killed if \parallel\Runtime executing task was killed.
5351
* @throws Future\Error\Cancelled if task was already cancelled.
5452
*/
55-
public function cancel(): bool
56-
{
57-
}
53+
public function cancel(): bool {}
5854
}

0 commit comments

Comments
 (0)