Passed
Pull Request — master (#96)
by Shinji
01:40
created

TargetProcessResolver::resolve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 7
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 12
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\Inspector\TargetProcess;
15
16
use PhpProfiler\Inspector\Settings\TargetProcessSettings\TargetProcessSettings;
17
use PhpProfiler\Lib\Process\Exec\TraceeExecutor;
18
use PhpProfiler\Lib\Process\ProcessSpecifier;
19
20
class TargetProcessResolver
21
{
22
    public function __construct(
23
        private TraceeExecutor $tracee_executor,
24
    ) {
25
    }
26
27
    public function resolve(
28
        TargetProcessSettings $target_process_settings
29
    ): ProcessSpecifier {
30
        if (!is_null($target_process_settings->pid)) {
31
            return new ProcessSpecifier($target_process_settings->pid);
32
        }
33
        assert(!is_null($target_process_settings->command));
34
        $pid = $this->tracee_executor->execute(
35
            $target_process_settings->command,
36
            $target_process_settings->arguments
37
        );
38
        return new ProcessSpecifier($pid);
39
    }
40
}
41