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

PhpReaderTask::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 21
rs 9.9
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\Lib\Concurrency\Amphp\Task;
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\Command\Inspector\Settings\GetTraceSettings;
19
use PhpProfiler\Command\Inspector\Settings\TargetProcessSettings;
20
use PhpProfiler\Command\Inspector\Settings\TraceLoopSettings;
21
use PhpProfiler\Command\Inspector\Worker\ReaderLoopProvider;
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
        GetTraceSettings $get_trace_settings
48
    ): Generator {
49
        $eg_address = $this->php_globals_finder->findExecutorGlobals($target_process_settings);
50
51
        $loop = $this->reader_loop_provider->getMainLoop(
52
            function () use ($get_trace_settings, $target_process_settings, $eg_address): \Generator {
53
54
                $call_trace = $this->executor_globals_reader->readCallTrace(
55
                    $target_process_settings->pid,
56
                    $target_process_settings->php_version,
57
                    $eg_address,
58
                    $get_trace_settings->depth
59
                );
60
                yield $this->channel->send(join(PHP_EOL, $call_trace) . PHP_EOL);
61
            },
62
            $loop_settings
63
        );
64
        yield from $loop->invoke();
65
    }
66
}
67