1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace WyriHaximus\React\ChildProcess\Messenger\ChildProcess; |
||||
6 | |||||
7 | use React\EventLoop\LoopInterface; |
||||
8 | use React\Promise\PromiseInterface; |
||||
9 | use Throwable; |
||||
10 | use WyriHaximus\React\ChildProcess\Messenger\ChildInterface; |
||||
11 | use WyriHaximus\React\ChildProcess\Messenger\Factory as MessengerFactory; |
||||
12 | use WyriHaximus\React\ChildProcess\Messenger\Messages\Payload; |
||||
13 | use WyriHaximus\React\ChildProcess\Messenger\Messenger; |
||||
14 | |||||
15 | use function is_subclass_of; |
||||
16 | use function React\Promise\resolve; |
||||
17 | |||||
18 | final class Process |
||||
19 | { |
||||
20 | private LoopInterface $loop; |
||||
21 | |||||
22 | private Messenger $messenger; |
||||
23 | |||||
24 | private function __construct(LoopInterface $loop, Messenger $messenger) |
||||
25 | { |
||||
26 | $this->loop = $loop; |
||||
27 | $this->messenger = $messenger; |
||||
28 | $this->messenger->registerRpc( |
||||
29 | MessengerFactory::PROCESS_REGISTER, |
||||
30 | function (Payload $payload): PromiseInterface { |
||||
31 | /** |
||||
32 | * @psalm-suppress PossiblyNullArgument |
||||
33 | */ |
||||
34 | if (! is_subclass_of($payload['className'], ChildInterface::class)) { |
||||
35 | throw DoesNotImplementChildInterfaceException::create($payload['className'] ?? ''); |
||||
36 | } |
||||
37 | |||||
38 | ($payload['className'])::create($this->messenger, $this->loop); |
||||
0 ignored issues
–
show
|
|||||
39 | $this->deregisterRpc(); |
||||
40 | |||||
41 | return resolve([]); |
||||
42 | } |
||||
43 | ); |
||||
44 | } |
||||
45 | |||||
46 | public static function create(LoopInterface $loop, Messenger $messenger): void |
||||
47 | { |
||||
48 | $reject = static function (Throwable $exeption) use ($loop): void { |
||||
0 ignored issues
–
show
The parameter
$exeption is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
49 | // $messenger->error(MessagesFactory::error($exeption->getFile())); |
||||
50 | $loop->addTimer(1, static function () use ($loop): void { |
||||
51 | $loop->stop(); |
||||
52 | }); |
||||
53 | }; |
||||
54 | |||||
55 | try { |
||||
56 | new Process($loop, $messenger); |
||||
57 | } catch (Throwable $throwable) { /** @phpstan-ignore-line */ |
||||
58 | $reject($throwable); |
||||
59 | } |
||||
60 | } |
||||
61 | |||||
62 | private function deregisterRpc(): void |
||||
63 | { |
||||
64 | $this->loop->futureTick(function (): void { |
||||
65 | $this->messenger->deregisterRpc(MessengerFactory::PROCESS_REGISTER); |
||||
66 | }); |
||||
67 | } |
||||
68 | } |
||||
69 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.