Skip to content

Commit 022ee96

Browse files
committed
Add support template types
1 parent 2a2c228 commit 022ee96

File tree

114 files changed

+1627
-363
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+1627
-363
lines changed

.github/workflows/ci.yml

+24
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,27 @@ jobs:
2929
coverage: xdebug
3030
- run: composer install
3131
- run: vendor/bin/phpunit --coverage-text
32+
PHPStan:
33+
name: PHPStan (PHP ${{ matrix.php }} on ${{ matrix.os }})
34+
runs-on: ${{ matrix.os }}
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
os:
39+
- ubuntu-20.04
40+
- windows-2019
41+
php:
42+
- 8.2
43+
- 8.1
44+
- 8.0
45+
- 7.4
46+
- 7.3
47+
- 7.2
48+
steps:
49+
- uses: actions/checkout@v3
50+
- uses: shivammathur/setup-php@v2
51+
with:
52+
php-version: ${{ matrix.php }}
53+
coverage: none
54+
- run: composer install
55+
- run: vendor/bin/phpstan

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
],
2222
"require": {
2323
"php": ">=7.0.0",
24-
"react/promise": "~2.2"
24+
"react/promise": "^3 || ~2.2"
2525
},
2626
"require-dev": {
2727
"satooshi/php-coveralls": "~1.0",
2828
"phpunit/phpunit": "^8.5 || ^9",
29-
"react/event-loop": "^1.0 || ^0.5 || ^0.4.2"
29+
"react/event-loop": "^1.0 || ^0.5 || ^0.4.2",
30+
"phpstan/phpstan": "^1.10"
3031
},
3132
"suggest": {
3233
"react/event-loop": "Used for scheduling async operations"

phpstan.neon.dist

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
parameters:
2+
level: max
3+
4+
paths:
5+
- src/
6+
- test/types/
7+
8+
fileExtensions:
9+
- php

src/Disposable/BinaryDisposable.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
*/
1313
class BinaryDisposable implements DisposableInterface
1414
{
15-
/** @var \Rx\DisposableInterface */
15+
/** @var ?\Rx\DisposableInterface */
1616
private $first;
1717

18-
/** @var \Rx\DisposableInterface */
18+
/** @var ?\Rx\DisposableInterface */
1919
private $second;
2020

2121
/** @var bool */
2222
protected $isDisposed = false;
2323

2424
/**
2525
* BinaryDisposable constructor.
26-
* @param $first
27-
* @param $second
26+
* @param DisposableInterface $first
27+
* @param DisposableInterface $second
2828
*/
2929
public function __construct(DisposableInterface $first, DisposableInterface $second)
3030
{
@@ -40,7 +40,9 @@ public function dispose()
4040

4141
$this->isDisposed = true;
4242

43+
/** @phpstan-ignore-next-line */
4344
$this->first->dispose();
45+
/** @phpstan-ignore-next-line */
4446
$this->second->dispose();
4547

4648
$this->first = null;

src/Disposable/CallbackDisposable.php

+7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88

99
class CallbackDisposable implements DisposableInterface
1010
{
11+
/**
12+
* @var callable
13+
*/
1114
private $action;
15+
16+
/**
17+
* @var bool
18+
*/
1219
private $disposed = false;
1320

1421
public function __construct(callable $action)

src/Disposable/CompositeDisposable.php

+19
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@
88

99
class CompositeDisposable implements DisposableInterface
1010
{
11+
/**
12+
* @var array<DisposableInterface>
13+
*/
1114
private $disposables;
15+
16+
/**
17+
* @var bool
18+
*/
1219
private $isDisposed = false;
1320

21+
/**
22+
* @param array<DisposableInterface> $disposables
23+
*/
1424
public function __construct(array $disposables = [])
1525
{
1626
$this->disposables = $disposables;
@@ -32,6 +42,9 @@ public function dispose()
3242
}
3343
}
3444

45+
/**
46+
* @return void
47+
*/
3548
public function add(DisposableInterface $disposable)
3649
{
3750
if ($this->isDisposed) {
@@ -65,11 +78,17 @@ public function contains(DisposableInterface $disposable): bool
6578
return in_array($disposable, $this->disposables, true);
6679
}
6780

81+
/**
82+
* @return int
83+
*/
6884
public function count()
6985
{
7086
return count($this->disposables);
7187
}
7288

89+
/**
90+
* @return void
91+
*/
7392
public function clear()
7493
{
7594
$disposables = $this->disposables;

src/Disposable/RefCountDisposable.php

+18
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@
88

99
class RefCountDisposable implements DisposableInterface
1010
{
11+
/**
12+
* @var int
13+
*/
1114
private $count = 0;
15+
16+
/**
17+
* @var DisposableInterface
18+
*/
1219
private $disposable;
20+
21+
/**
22+
* @var bool
23+
*/
1324
private $isDisposed = false;
25+
26+
/**
27+
* @var bool
28+
*/
1429
private $isPrimaryDisposed = false;
1530

1631
public function __construct(DisposableInterface $disposable)
@@ -32,6 +47,9 @@ public function dispose()
3247
}
3348
}
3449

50+
/**
51+
* @return DisposableInterface
52+
*/
3553
public function getDisposable()
3654
{
3755
if (!$this->isDisposed) {

src/Disposable/SerialDisposable.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class SerialDisposable implements DisposableInterface
1515
/** @var bool */
1616
private $isDisposed = false;
1717

18-
/** @var DisposableInterface */
18+
/** @var ?DisposableInterface */
1919
private $disposable = null;
2020

2121
public function dispose()
@@ -34,7 +34,7 @@ public function dispose()
3434
}
3535

3636
/**
37-
* @return DisposableInterface
37+
* @return ?DisposableInterface
3838
*/
3939
public function getDisposable()
4040
{
@@ -43,6 +43,7 @@ public function getDisposable()
4343

4444
/**
4545
* @param DisposableInterface $disposable
46+
* @return void
4647
*/
4748
public function setDisposable(DisposableInterface $disposable)
4849
{

src/Disposable/SingleAssignmentDisposable.php

+16
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99

1010
class SingleAssignmentDisposable implements DisposableInterface
1111
{
12+
/**
13+
* @var ?DisposableInterface
14+
*/
1215
private $current;
16+
17+
/**
18+
* @var bool
19+
*/
1320
private $isDisposed = false;
1421

1522
public function dispose()
@@ -27,6 +34,9 @@ public function dispose()
2734
}
2835
}
2936

37+
/**
38+
* @return void
39+
*/
3040
public function setDisposable(DisposableInterface $disposable = null)
3141
{
3242
if ($this->current) {
@@ -42,11 +52,17 @@ public function setDisposable(DisposableInterface $disposable = null)
4252
}
4353
}
4454

55+
/**
56+
* @return DisposableInterface|null
57+
*/
4558
public function getDisposable()
4659
{
4760
return $this->current;
4861
}
4962

63+
/**
64+
* @return bool
65+
*/
5066
public function isDisposed()
5167
{
5268
return $this->isDisposed;

src/DisposableInterface.php

+3
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66

77
interface DisposableInterface
88
{
9+
/**
10+
* @return void
11+
*/
912
public function dispose();
1013
}

src/Notification.php

+23-11
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,45 @@
99
*/
1010
abstract class Notification
1111
{
12-
private $kind;
13-
1412
/**
15-
* @param mixed $kind Kind of notification
13+
* @template T
14+
* @param (callable(T): void)|ObserverInterface $observerOrOnNext
15+
* @param (callable(\Throwable): void) $onError
16+
* @param (callable(): void) $onCompleted
17+
* @return void
1618
*/
17-
public function __construct($kind)
18-
{
19-
$this->kind = $kind;
20-
}
21-
22-
public function accept($observerOrOnNext, $onError = null, $onCompleted = null)
19+
public function accept($observerOrOnNext, callable $onError = null, callable $onCompleted = null)
2320
{
2421
if (null === $onError && null === $onCompleted && $observerOrOnNext instanceof ObserverInterface) {
2522
$this->doAcceptObservable($observerOrOnNext);
2623

2724
return;
2825
}
2926

30-
return $this->doAccept($observerOrOnNext, $onError, $onCompleted);
27+
assert(is_callable($observerOrOnNext));
28+
$this->doAccept($observerOrOnNext, $onError, $onCompleted);
3129
}
3230

31+
/**
32+
* @param mixed $other
33+
*/
3334
public function equals($other): bool
3435
{
36+
/** @phpstan-ignore-next-line */
3537
return (string)$this === (string)$other;
3638
}
3739

40+
/**
41+
* @return void
42+
*/
3843
abstract protected function doAcceptObservable(ObserverInterface $observer);
3944

40-
abstract protected function doAccept($onNext, $onError, $onCompleted);
45+
/**
46+
* @template T
47+
* @param (callable(T): void) $onNext
48+
* @param (callable(\Throwable): void) $onError
49+
* @param (callable(): void) $onCompleted
50+
* @return void
51+
*/
52+
abstract protected function doAccept(callable $onNext, callable $onError = null, callable $onCompleted = null);
4153
}

src/Notification/OnCompletedNotification.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@
99

1010
class OnCompletedNotification extends Notification
1111
{
12-
public function __construct()
13-
{
14-
parent::__construct('C');
15-
}
16-
12+
/**
13+
* @return void
14+
*/
1715
protected function doAcceptObservable(ObserverInterface $observer)
1816
{
1917
$observer->onCompleted();
2018
}
2119

22-
protected function doAccept($onNext, $onError, $onCompleted)
20+
protected function doAccept(callable $onNext, callable $onError = null, callable $onCompleted = null)
2321
{
22+
assert(is_callable($onCompleted));
2423
$onCompleted();
2524
}
2625

src/Notification/OnErrorNotification.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,27 @@
99

1010
class OnErrorNotification extends Notification
1111
{
12+
/**
13+
* @var \Throwable
14+
*/
1215
private $exception;
1316

1417
public function __construct(\Throwable $exception)
1518
{
16-
parent::__construct('E');
17-
1819
$this->exception = $exception;
1920
}
2021

22+
/**
23+
* @return void
24+
*/
2125
protected function doAcceptObservable(ObserverInterface $observer)
2226
{
2327
$observer->onError($this->exception);
2428
}
2529

26-
protected function doAccept($onNext, $onError, $onCompleted)
30+
protected function doAccept(callable $onNext, callable $onError = null, callable $onCompleted = null)
2731
{
32+
assert(is_callable($onError));
2833
$onError($this->exception);
2934
}
3035

0 commit comments

Comments
 (0)