Passed
Push — master ( 918514...b89e50 )
by Biao
03:27
created

PrometheusCollectorProcess::onStop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Hhxsv5\LaravelS\Components\Prometheus;
4
5
use Hhxsv5\LaravelS\Components\Prometheus\Collectors\SwooleWorkerCollector;
6
use Hhxsv5\LaravelS\Swoole\Process\CustomProcessInterface;
7
use Swoole\Http\Server;
8
use Swoole\Process;
9
use Swoole\Timer;
10
11
class PrometheusCollectorProcess implements CustomProcessInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class PrometheusCollectorProcess
Loading history...
12
{
13
    private static $timerId;
0 ignored issues
show
Coding Style introduced by
Private member variable "timerId" must be prefixed with an underscore
Loading history...
14
15
    public static function callback(Server $swoole, Process $process)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function callback()
Loading history...
16
    {
17
        /**@var \Hhxsv5\LaravelS\Components\Prometheus\PrometheusCollector $collector */
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
18
        $collector = app(SwooleWorkerCollector::class);
0 ignored issues
show
Bug introduced by
The function app 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

18
        $collector = /** @scrutinizer ignore-call */ app(SwooleWorkerCollector::class);
Loading history...
19
        $workerNum = $swoole->setting['worker_num'];
20
        $taskWorkerNum = isset($swoole->setting['task_worker_num']) ? $swoole->setting['task_worker_num'] : 0;
21
        $totalNum = $workerNum + $taskWorkerNum - 1;
22
        $workerIds = range(0, $totalNum);
23
        $runJob = function () use ($swoole, $workerIds, $collector) {
24
            foreach ($workerIds as $workerId) {
25
                $swoole->sendMessage($collector, $workerId);
26
            }
27
        };
28
29
        $interval = config('prometheus.collect_metrics_interval', 10) * 1000;
0 ignored issues
show
Bug introduced by
The function config 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

29
        $interval = /** @scrutinizer ignore-call */ config('prometheus.collect_metrics_interval', 10) * 1000;
Loading history...
30
        self::$timerId = Timer::tick($interval, $runJob);
31
    }
32
33
    public static function onReload(Server $swoole, Process $process)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function onReload()
Loading history...
34
    {
35
        Timer::clear(self::$timerId);
36
    }
37
38
    public static function onStop(Server $swoole, Process $process)
0 ignored issues
show
Unused Code introduced by
The parameter $swoole is not used and could be removed. ( Ignorable by Annotation )

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

38
    public static function onStop(/** @scrutinizer ignore-unused */ Server $swoole, Process $process)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Missing doc comment for function onStop()
Loading history...
Unused Code introduced by
The parameter $process is not used and could be removed. ( Ignorable by Annotation )

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

38
    public static function onStop(Server $swoole, /** @scrutinizer ignore-unused */ Process $process)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
    {
40
        Timer::clear(self::$timerId);
41
    }
42
}