Passed
Push — master ( c2a6de...b42a4e )
by Shinji
01:35
created

GetEgAddressCommand::writeError()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 4
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\Command\Inspector;
15
16
use PhpProfiler\Command\CommandSettingsException;
17
use PhpProfiler\Command\Inspector\Settings\TargetProcessSettings;
18
use PhpProfiler\Lib\Elf\Parser\ElfParserException;
19
use PhpProfiler\Lib\Elf\Tls\TlsFinderException;
20
use PhpProfiler\Lib\PhpProcessReader\PhpGlobalsFinder;
21
use PhpProfiler\Lib\Process\MemoryReader\MemoryReaderException;
22
use PhpProfiler\Lib\Elf\Process\ProcessSymbolReaderException;
23
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...
24
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...
25
use Symfony\Component\Console\Input\InputOption;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputOption 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...
26
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...
27
28
/**
29
 * Class GetEgAddressCommand
30
 * @package PhpProfiler\Command\Inspector
31
 */
32
final class GetEgAddressCommand extends Command
33
{
34
    private PhpGlobalsFinder $php_globals_finder;
35
36
    /**
37
     * GetEgAddressCommand constructor.
38
     *
39
     * @param PhpGlobalsFinder $php_globals_finder
40
     * @param string|null $name
41
     */
42
    public function __construct(
43
        PhpGlobalsFinder $php_globals_finder
44
    ) {
45
        parent::__construct();
46
        $this->php_globals_finder = $php_globals_finder;
47
    }
48
49
    public function configure(): void
50
    {
51
        $this->setName('inspector:eg_address')
52
            ->setDescription('get EG address from an outer process or thread')
53
            ->addOption('pid', 'p', InputOption::VALUE_REQUIRED, 'process id');
54
    }
55
56
    /**
57
     * @param InputInterface $input
58
     * @param OutputInterface $output
59
     * @return int
60
     * @throws MemoryReaderException
61
     * @throws ProcessSymbolReaderException
62
     * @throws ElfParserException
63
     * @throws TlsFinderException
64
     * @throws CommandSettingsException
65
     */
66
    public function execute(InputInterface $input, OutputInterface $output): int
67
    {
68
        $target_process_settings = TargetProcessSettings::fromConsoleInput($input);
69
70
        $output->writeln(
71
            '0x' . dechex($this->php_globals_finder->findExecutorGlobals($target_process_settings->pid))
72
        );
73
74
        return 0;
75
    }
76
}
77