Porting::porting()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 4
dl 0
loc 16
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Server porting
4
 * User: moyo
5
 * Date: 2018/8/27
6
 * Time: 10:49 AM
7
 */
8
9
namespace Carno\Socket\Powered\Swoole\Chips;
10
11
use Carno\Net\Events;
12
use Carno\Socket\Contracts\TServer;
13
use Carno\Socket\Options;
14
use Swoole\Server as SWServer;
0 ignored issues
show
Bug introduced by
The type Swoole\Server 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...
15
use Swoole\Server\Port as SWPorted;
0 ignored issues
show
Bug introduced by
The type Swoole\Server\Port 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...
16
17
trait Porting
18
{
19
    /**
20
     * @param SWServer $master
21
     * @param SWPorted $ported
22
     * @param Events $events
23
     * @param Options $options
24
     * @return TServer
25
     */
26
    public function porting(SWServer $master, SWPorted $ported, Events $events, Options $options = null) : TServer
27
    {
28
        $this->server = $master;
0 ignored issues
show
Bug Best Practice introduced by
The property server does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29
        $this->events = $events;
0 ignored issues
show
Bug Best Practice introduced by
The property events does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
31
        $this->registerEvs($ported, ['bufferFull', 'bufferEmpty']);
0 ignored issues
show
Bug introduced by
It seems like registerEvs() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

31
        $this->/** @scrutinizer ignore-call */ 
32
               registerEvs($ported, ['bufferFull', 'bufferEmpty']);
Loading history...
32
33
        $this->registerEvs($ported, $this->k2evs($events->keys(), [
34
            Events\Socket::CONNECTED => 'connect',
35
            Events\Socket::RECEIVED => 'receive',
36
            Events\Socket::CLOSED => 'close',
37
        ]));
38
39
        $options && $this->serverConfig($ported, $options->config());
0 ignored issues
show
Bug introduced by
It seems like serverConfig() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

39
        $options && $this->/** @scrutinizer ignore-call */ serverConfig($ported, $options->config());
Loading history...
40
41
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Carno\Socket\Powered\Swoole\Chips\Porting which is incompatible with the type-hinted return Carno\Socket\Contracts\TServer.
Loading history...
42
    }
43
44
    /**
45
     * @param array $keys
46
     * @param array $map
47
     * @return array
48
     */
49
    private function k2evs(array $keys, array $map)
50
    {
51
        $evs = [];
52
53
        foreach ($keys as $key) {
54
            isset($map[$key]) && $evs[] = $map[$key];
55
        }
56
57
        return $evs;
58
    }
59
}
60