Issues (27)

src/Plugins/ServerPorting.php (6 issues)

Labels
Severity
1
<?php
2
/**
3
 * TCP accelerator for HRPC server
4
 * User: moyo
5
 * Date: 2018/7/30
6
 * Time: 12:07 PM
7
 */
8
9
namespace Carno\HRPC\Accel\Plugins;
10
11
use Carno\Consul\Types\Tagging;
0 ignored issues
show
The type Carno\Consul\Types\Tagging 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...
12
use Carno\Container\DI;
0 ignored issues
show
The type Carno\Container\DI 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...
13
use Carno\HRPC\Accel\Marking;
14
use Carno\HRPC\Accel\Server;
15
use Carno\Net\Address;
16
use Carno\Net\Contracts\Conn;
17
use Carno\Net\Events;
18
use Carno\RPC\Service\Dispatcher;
0 ignored issues
show
The type Carno\RPC\Service\Dispatcher 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 Carno\Serving\Contracts\Plugins;
0 ignored issues
show
The type Carno\Serving\Contracts\Plugins 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
21
class ServerPorting implements Plugins
22
{
23
    /**
24
     * @var Address
25
     */
26
    private $listen = null;
27
28
    /**
29
     * @var Server
30
     */
31
    private $server = null;
32
33
    /**
34
     * ServerPorting constructor.
35
     * @param Address $listen
36
     */
37
    public function __construct(Address $listen)
38
    {
39
        $this->listen = $listen;
40
    }
41
42
    /**
43
     * @return bool
44
     */
45
    public function enabled() : bool
46
    {
47
        return !debug() &&
0 ignored issues
show
The function debug 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

47
        return !/** @scrutinizer ignore-call */ debug() &&
Loading history...
48
            $this->listen->valid() &&
49
            DI::has(Tagging::class) &&
50
            DI::has(Dispatcher::class) &&
51
            version_compare(SWOOLE_VERSION, '1.8.0') >= 0
0 ignored issues
show
The constant Carno\HRPC\Accel\Plugins\SWOOLE_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
52
        ;
53
    }
54
55
    /**
56
     * @param Events $events
57
     */
58
    public function hooking(Events $events) : void
59
    {
60
        $events
61
        ->attach(Events\Server::CREATED, function (Conn $serv) {
62
            ($this->server = new Server($this->listen, $serv->server()->raw(), $serv->events()))->serve();
63
            if ($port = $this->server->ported()) {
64
                /**
65
                 * @var Tagging $tagger
66
                 */
67
                $tagger = DI::get(Tagging::class);
68
                $tagger->setTags(Marking::viaTCP($port));
69
                logger('hrpc-accel')->info('TCP accelerator started', ['port' => $port]);
70
            } else {
71
                logger('hrpc-accel')->notice('TCP accelerator startup failed .. skip');
72
            }
73
        })
74
        ->attach(Events\Worker::STOPPED, function () {
75
            $this->server->shutdown();
76
        });
77
    }
78
}
79