Passed
Pull Request — master (#9)
by Shinji
02:03
created

PhpReaderTask::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 5
dl 0
loc 30
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the sj-i/php-profiler package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace PhpProfiler\Inspector\Daemon\Reader;
15
16
use Amp\Parallel\Sync\Channel;
0 ignored issues
show
Bug introduced by
The type Amp\Parallel\Sync\Channel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Generator;
18
use PhpProfiler\Inspector\Daemon\Dispatcher\Message\TraceMessage;
19
use PhpProfiler\Inspector\Settings\GetTraceSettings;
20
use PhpProfiler\Inspector\Settings\TargetPhpSettings;
21
use PhpProfiler\Inspector\Settings\TargetProcessSettings;
22
use PhpProfiler\Inspector\Settings\TraceLoopSettings;
23
use PhpProfiler\Lib\PhpProcessReader\PhpGlobalsFinder;
24
use PhpProfiler\Lib\PhpProcessReader\PhpMemoryReader\ExecutorGlobalsReader;
25
26
final class PhpReaderTask implements PhpReaderTaskInterface
27
{
28
    private PhpGlobalsFinder $php_globals_finder;
29
    private ExecutorGlobalsReader $executor_globals_reader;
30
    private ReaderLoopProvider $reader_loop_provider;
31
32
    public function __construct(
33
        PhpGlobalsFinder $php_globals_finder,
34
        ExecutorGlobalsReader $executor_globals_reader,
35
        ReaderLoopProvider $reader_loop_provider
36
    ) {
37
        $this->php_globals_finder = $php_globals_finder;
38
        $this->executor_globals_reader = $executor_globals_reader;
39
        $this->reader_loop_provider = $reader_loop_provider;
40
    }
41
42
    public function run(
43
        Channel $channel,
44
        TargetProcessSettings $target_process_settings,
45
        TraceLoopSettings $loop_settings,
46
        TargetPhpSettings $target_php_settings,
47
        GetTraceSettings $get_trace_settings
48
    ): Generator {
49
        $eg_address = $this->php_globals_finder->findExecutorGlobals($target_process_settings, $target_php_settings);
50
51
        $loop = $this->reader_loop_provider->getMainLoop(
52
            function () use (
53
                $channel,
54
                $get_trace_settings,
55
                $target_process_settings,
56
                $target_php_settings,
57
                $eg_address
58
            ): \Generator {
59
                $call_trace = $this->executor_globals_reader->readCallTrace(
60
                    $target_process_settings->pid,
61
                    $target_php_settings->php_version,
62
                    $eg_address,
63
                    $get_trace_settings->depth
64
                );
65
                yield $channel->send(
66
                    new TraceMessage(join(PHP_EOL, $call_trace) . PHP_EOL)
67
                );
68
            },
69
            $loop_settings
70
        );
71
        yield from $loop->invoke();
72
    }
73
}
74