Completed
Push — master ( d61801...46edea )
by Biao
05:21
created

ApolloServiceProcess   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 30
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A onReload() 0 4 1
A getDefinition() 0 7 1
A callback() 0 7 1
1
<?php
2
3
namespace Hhxsv5\LaravelS\Swoole\Process;
4
5
use Hhxsv5\LaravelS\Components\Apollo\Apollo;
6
use Swoole\Coroutine;
7
use Swoole\Http\Server;
8
use Swoole\Process;
9
10
class ApolloServiceProcess implements CustomProcessInterface
11
{
12
    /**@var Apollo $apollo */
13
    protected static $apollo;
14
15
    public static function getDefinition()
16
    {
17
        return [
18
            'apollo-service' => [
19
                'class'    => self::class,
20
                'redirect' => false,
21
                'pipe'     => 0,
22
            ],
23
        ];
24
    }
25
26
    public static function callback(Server $swoole, Process $process)
27
    {
28
        self::$apollo = Apollo::createFromEnv();
29
        self::$apollo->startWatchNotification(function (array $notifications) use ($swoole) {
0 ignored issues
show
Unused Code introduced by
The parameter $notifications 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

29
        self::$apollo->startWatchNotification(function (/** @scrutinizer ignore-unused */ array $notifications) use ($swoole) {

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...
30
            self::$apollo->pullAllAndSave(base_path('.env'), false);
31
            $swoole->reload();
32
            Coroutine::sleep(3);
33
        });
34
    }
35
36
    public static function onReload(Server $swoole, Process $process)
37
    {
38
        // Stop the process...
39
        self::$apollo->stopWatchNotification();
40
    }
41
}