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

PhpReaderTask   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 47
c 0
b 0
f 0
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A run() 0 28 1
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
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
        TargetProcessSettings $target_process_settings,
47
        TraceLoopSettings $loop_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(
67
                    new TraceMessage(join(PHP_EOL, $call_trace) . PHP_EOL)
68
                );
69
            },
70
            $loop_settings
71
        );
72
        yield from $loop->invoke();
73
    }
74
}
75