Process::onReload()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Hhxsv5\LaravelS\Components\Apollo;
4
5
use Hhxsv5\LaravelS\Console\Portal;
6
use Hhxsv5\LaravelS\Swoole\Coroutine\Context;
7
use Hhxsv5\LaravelS\Swoole\Process\CustomProcessInterface;
8
use Swoole\Coroutine;
9
use Swoole\Http\Server;
10
use Swoole\Process as SwooleProcess;
11
12
class Process implements CustomProcessInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Process
Loading history...
13
{
14
    /**@var Client $apollo */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
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...
15
    protected static $apollo;
16
17
    public static function getDefinition()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getDefinition()
Loading history...
18
    {
19
        return [
20
            'apollo' => [
21
                'class'    => static::class,
22
                'redirect' => false,
23
                'pipe'     => 0,
24
                'enable'   => (bool)getenv('ENABLE_APOLLO'),
25
            ],
26
        ];
27
    }
28
29
    public static function callback(Server $swoole, SwooleProcess $process)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function callback()
Loading history...
30
    {
31
        $filename = base_path('.env');
0 ignored issues
show
Bug introduced by
The function base_path 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

31
        $filename = /** @scrutinizer ignore-call */ base_path('.env');
Loading history...
32
        if (isset($_ENV['_ENV'])) {
33
            $filename .= '.' . $_ENV['_ENV'];
34
        }
35
36
        self::$apollo = Client::createFromEnv();
37
        self::$apollo->startWatchNotification(function (array $notifications) use ($process, $filename) {
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

37
        self::$apollo->startWatchNotification(function (/** @scrutinizer ignore-unused */ array $notifications) use ($process, $filename) {

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
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Unused Code introduced by
The import $process is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
38
            $configs = self::$apollo->pullAllAndSave($filename);
39
            app('log')->info('[ApolloProcess] Pull all configurations', $configs);
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

39
            /** @scrutinizer ignore-call */ 
40
            app('log')->info('[ApolloProcess] Pull all configurations', $configs);
Loading history...
40
            Portal::runLaravelSCommand(base_path(), 'reload');
0 ignored issues
show
Bug introduced by
The function base_path 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

40
            Portal::runLaravelSCommand(/** @scrutinizer ignore-call */ base_path(), 'reload');
Loading history...
41
            if (Context::inCoroutine()) {
42
                Coroutine::sleep(5);
43
            } else {
44
                sleep(5);
45
            }
46
        });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
47
    }
48
49
    public static function onReload(Server $swoole, SwooleProcess $process)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function onReload()
Loading history...
50
    {
51
        // Stop the process...
52
        self::$apollo->stopWatchNotification();
53
    }
54
}