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

PhpReaderTask::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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