|
9 | 9 | */
|
10 | 10 | abstract class Notification
|
11 | 11 | {
|
12 |
| - private $kind; |
13 |
| - |
14 | 12 | /**
|
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 |
16 | 18 | */
|
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) |
23 | 20 | {
|
24 | 21 | if (null === $onError && null === $onCompleted && $observerOrOnNext instanceof ObserverInterface) {
|
25 | 22 | $this->doAcceptObservable($observerOrOnNext);
|
26 | 23 |
|
27 | 24 | return;
|
28 | 25 | }
|
29 | 26 |
|
30 |
| - return $this->doAccept($observerOrOnNext, $onError, $onCompleted); |
| 27 | + assert(is_callable($observerOrOnNext)); |
| 28 | + $this->doAccept($observerOrOnNext, $onError, $onCompleted); |
31 | 29 | }
|
32 | 30 |
|
| 31 | + /** |
| 32 | + * @param mixed $other |
| 33 | + */ |
33 | 34 | public function equals($other): bool
|
34 | 35 | {
|
| 36 | + /** @phpstan-ignore-next-line */ |
35 | 37 | return (string)$this === (string)$other;
|
36 | 38 | }
|
37 | 39 |
|
| 40 | + /** |
| 41 | + * @return void |
| 42 | + */ |
38 | 43 | abstract protected function doAcceptObservable(ObserverInterface $observer);
|
39 | 44 |
|
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); |
41 | 53 | }
|
0 commit comments