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

DaemonCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
nc 1
nop 0
dl 0
loc 4
c 1
b 0
f 1
cc 1
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 Amp\Loop;
0 ignored issues
show
Bug introduced by
The type Amp\Loop 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 Amp\Promise;
0 ignored issues
show
Bug introduced by
The type Amp\Promise 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...
18
use Amp\Parallel\Context;
0 ignored issues
show
Bug introduced by
The type Amp\Parallel\Context 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...
19
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...
20
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...
21
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...
22
23
class DaemonCommand extends Command
24
{
25
    private DaemonLoopProvider $loop_provider;
0 ignored issues
show
Bug introduced by
The type PhpProfiler\Command\Inspector\DaemonLoopProvider 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
27
    public function __construct(DaemonLoopProvider $loop_provider)
28
    {
29
        $this->loop_provider = $loop_provider;
30
        parent::__construct();
31
    }
32
33
    public function configure(): void
34
    {
35
        $this->setName('inspector:daemon')
36
            ->setDescription('periodically get running function name from an outer process or thread');
37
    }
38
39
    /**
40
     * @param InputInterface $input
41
     * @param OutputInterface $output
42
     * @return int
43
     */
44
    public function execute(InputInterface $input, OutputInterface $output): int
45
    {
46
        $context = Context\create(__DIR__ . '/Worker/php-searcher.php');
0 ignored issues
show
Bug introduced by
The function create was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

46
        $context = /** @scrutinizer ignore-call */ Context\create(__DIR__ . '/Worker/php-searcher.php');
Loading history...
47
        /** @var int $searcher_pid */
48
        $searcher_pid = Promise\wait($context->start());
0 ignored issues
show
Unused Code introduced by
The assignment to $searcher_pid is dead and can be removed.
Loading history...
Bug introduced by
The function wait was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

48
        $searcher_pid = /** @scrutinizer ignore-call */ Promise\wait($context->start());
Loading history...
49
        /** @var int[] $pid_list */
50
        $pid_list = Promise\wait($context->receive());
51
        $readers = [];
52
        foreach ($pid_list as $pid) {
53
            $context = Context\create(__DIR__ . '/Worker/php-reader.php');
54
            Promise\wait($context->start());
55
            Promise\wait($context->send($pid));
56
            $readers[$pid] = $context;
57
        }
58
        Loop::run(function () use (&$readers, $output) {
59
            Loop::repeat(10, function () use (&$readers, $output) {
60
                if (empty($readers)) {
61
                    return false;
62
                }
63
                $promises = [];
64
                foreach ($readers as $pid => $reader) {
65
                    if (!$reader->isRunning()) {
66
                        unset($readers[$pid]);
67
                        continue;
68
                    }
69
                    $promises[] = \Amp\call(
0 ignored issues
show
Bug introduced by
The function call was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

69
                    $promises[] = /** @scrutinizer ignore-call */ \Amp\call(
Loading history...
70
                        function () use ($reader, &$readers, $pid, $output) {
71
                            /** @var string */
72
                            unset($readers[$pid]);
73
                            $result = yield $reader->receive();
74
                            $output->write($result);
75
                            $readers[$pid] = $reader;
76
                        }
77
                    );
78
                }
79
                yield $promises;
80
            });
81
        });
82
83
        return 0;
84
    }
85
}
86