Passed
Pull Request — master (#9)
by Shinji
01:54
created

PhpReaderTask::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 4
dl 0
loc 26
rs 9.7333
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\Settings\GetTraceSettings;
19
use PhpProfiler\Inspector\Settings\TargetPhpSettings;
20
use PhpProfiler\Inspector\Settings\TargetProcessSettings;
21
use PhpProfiler\Inspector\Settings\TraceLoopSettings;
22
use PhpProfiler\Lib\PhpProcessReader\PhpGlobalsFinder;
23
use PhpProfiler\Lib\PhpProcessReader\PhpMemoryReader\ExecutorGlobalsReader;
24
25
final class PhpReaderTask
26
{
27
    private Channel $channel;
28
    private PhpGlobalsFinder $php_globals_finder;
29
    private ExecutorGlobalsReader $executor_globals_reader;
30
    private ReaderLoopProvider $reader_loop_provider;
31
32
    public function __construct(
33
        Channel $channel,
34
        PhpGlobalsFinder $php_globals_finder,
35
        ExecutorGlobalsReader $executor_globals_reader,
36
        ReaderLoopProvider $reader_loop_provider
37
    ) {
38
        $this->channel = $channel;
39
        $this->php_globals_finder = $php_globals_finder;
40
        $this->executor_globals_reader = $executor_globals_reader;
41
        $this->reader_loop_provider = $reader_loop_provider;
42
    }
43
44
    public function run(
45
        TraceLoopSettings $loop_settings,
46
        TargetProcessSettings $target_process_settings,
47
        TargetPhpSettings $target_php_settings,
48
        GetTraceSettings $get_trace_settings
49
    ): Generator {
50
        $eg_address = $this->php_globals_finder->findExecutorGlobals($target_process_settings, $target_php_settings);
51
52
        $loop = $this->reader_loop_provider->getMainLoop(
53
            function () use (
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 $this->channel->send(join(PHP_EOL, $call_trace) . PHP_EOL);
66
            },
67
            $loop_settings
68
        );
69
        yield from $loop->invoke();
70
    }
71
}
72