GetEgAddressCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 6
Bugs 2 Features 1
Metric Value
eloc 20
c 6
b 2
f 1
dl 0
loc 54
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A configure() 0 7 1
A execute() 0 26 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\Command\Inspector;
15
16
use PhpProfiler\Inspector\RetryingLoopProvider;
17
use PhpProfiler\Inspector\Settings\InspectorSettingsException;
18
use PhpProfiler\Inspector\Settings\TargetPhpSettings\TargetPhpSettingsFromConsoleInput;
19
use PhpProfiler\Inspector\Settings\TargetProcessSettings\TargetProcessSettingsFromConsoleInput;
20
use PhpProfiler\Inspector\TargetProcess\TargetProcessResolver;
21
use PhpProfiler\Lib\Elf\Parser\ElfParserException;
22
use PhpProfiler\Lib\Elf\Tls\TlsFinderException;
23
use PhpProfiler\Lib\PhpProcessReader\PhpGlobalsFinder;
24
use PhpProfiler\Lib\Process\MemoryReader\MemoryReaderException;
25
use PhpProfiler\Lib\Elf\Process\ProcessSymbolReaderException;
26
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command 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...
27
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputInterface 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...
28
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\OutputInterface 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...
29
30
use function dechex;
31
use function sprintf;
32
33
final class GetEgAddressCommand extends Command
34
{
35
    public function __construct(
36
        private PhpGlobalsFinder $php_globals_finder,
37
        private TargetPhpSettingsFromConsoleInput $target_php_settings_from_console_input,
38
        private TargetProcessSettingsFromConsoleInput $target_process_settings_from_console_input,
39
        private TargetProcessResolver $target_process_resolver,
40
        private RetryingLoopProvider $retrying_loop_provider,
41
    ) {
42
        parent::__construct();
43
    }
44
45
    public function configure(): void
46
    {
47
        $this->setName('inspector:eg_address')
48
            ->setDescription('get EG address from an outer process or thread')
49
        ;
50
        $this->target_process_settings_from_console_input->setOptions($this);
51
        $this->target_php_settings_from_console_input->setOptions($this);
52
    }
53
54
    /**
55
     * @throws MemoryReaderException
56
     * @throws ProcessSymbolReaderException
57
     * @throws ElfParserException
58
     * @throws TlsFinderException
59
     * @throws InspectorSettingsException
60
     */
61
    public function execute(InputInterface $input, OutputInterface $output): int
62
    {
63
        $target_php_settings = $this->target_php_settings_from_console_input->createSettings($input);
64
        $target_process_settings = $this->target_process_settings_from_console_input->createSettings($input);
65
66
        $process_specifier = $this->target_process_resolver->resolve($target_process_settings);
67
68
        // see the comment at GetTraceCommand::execute()
69
        $eg_address = $this->retrying_loop_provider->do(
70
            try: fn () => $this->php_globals_finder->findExecutorGlobals(
71
                $process_specifier,
72
                $target_php_settings
73
            ),
74
            retry_on: [\Throwable::class],
75
            max_retry: 10,
76
            interval_on_retry_ns: 1000 * 1000 * 10,
77
        );
78
79
        $output->writeln(
80
            sprintf(
81
                '0x%s',
82
                dechex($eg_address)
0 ignored issues
show
Bug introduced by
$eg_address of type PhpProfiler\Inspector\T is incompatible with the type integer expected by parameter $num of dechex(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
                dechex(/** @scrutinizer ignore-type */ $eg_address)
Loading history...
83
            )
84
        );
85
86
        return 0;
87
    }
88
}
89