Passed
Push — master ( 6205c3...b22921 )
by Sergii
10:29
created

Client   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 143
Duplicated Lines 0 %

Test Coverage

Coverage 82.93%

Importance

Changes 0
Metric Value
dl 0
loc 143
ccs 34
cts 41
cp 0.8293
rs 10
c 0
b 0
f 0
wmc 18

8 Methods

Rating   Name   Duplication   Size   Complexity  
D includeRoutes() 0 34 10
A start() 0 3 1
A onSessionStart() 0 3 1
A setRoutePath() 0 3 1
A isConnectionRetry() 0 3 1
A retryConnection() 0 7 2
A onClose() 0 5 1
A setConnectionRetry() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 *
5
 * @author Donii Sergii <[email protected]>
6
 * Date: 10/25/17
7
 * Time: 12:18 PM
8
 */
9
10
namespace sonrac\WAMP;
11
12
use Thruway\ClientSession;
13
use Thruway\Peer\Client as PeerClient;
14
15
/**
16
 * Class Client
17
 * Client class.
18
 *
19
 * @author Donii Sergii <[email protected]>
20
 */
21
class Client extends PeerClient
22
{
23
    /**
24
     * Path to WAMP routes
25
     *
26
     * @var string|null
27
     *
28
     * @author Donii Sergii <[email protected]>
29
     */
30
    protected $routePath = null;
31
32
    /**
33
     * Retry connection on close or no
34
     *
35
     * @var bool
36
     *
37
     * @author Donii Sergii <[email protected]>
38
     */
39
    protected $connectionRetry = true;
40
41
    /**
42
     * Realm
43
     *
44
     * @var string
45
     *
46
     * @author Donii Sergii <[email protected]>
47
     */
48
    protected $realm;
49
50
    /**
51
     * Session start event
52
     *
53
     * @param \Thruway\ClientSession                $session
54
     * @param \Thruway\Transport\TransportInterface $transport
55
     *
56
     * @author Donii Sergii <[email protected]>
57
     */
58 5
    public function onSessionStart($session, $transport)
59
    {
60 5
        $this->includeRoutes($session, $transport);
61 5
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 3
    public function start($startLoop = true)
67
    {
68 3
        parent::start($startLoop);
69 3
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 2
    public function onClose($reason, $retry = true)
75
    {
76 2
        $this->connectionRetry = $retry;
77
78 2
        parent::onClose($reason);
79 2
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 2
    public function retryConnection()
85
    {
86 2
        if (!$this->connectionRetry) {
87 2
            return;
88
        }
89
90
        return parent::retryConnection();
0 ignored issues
show
Bug introduced by
Are you sure the usage of parent::retryConnection() targeting Thruway\Peer\Client::retryConnection() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
91
    }
92
93 2
    public function setRoutePath($path)
94
    {
95 2
        $this->routePath = $path;
96 2
    }
97
98
    /**
99
     * Set attribute connectionRetry
100
     *
101
     * @return bool
102
     *
103
     * @author Donii Sergii <[email protected]>
104
     */
105
    public function isConnectionRetry(): bool
106
    {
107
        return $this->connectionRetry;
108
    }
109
110
    /**
111
     * Set connection retry
112
     *
113
     * @param bool $connectionRetry
114
     *
115
     * @author Donii Sergii <[email protected]>
116
     */
117
    public function setConnectionRetry(bool $connectionRetry)
118
    {
119
        $this->connectionRetry = $connectionRetry;
120
    }
121
122
    /**
123
     * Include routes
124
     *
125
     * @param \Thruway\ClientSession                $session   Client session
126
     * @param \Thruway\Transport\TransportInterface $transport Transport provider
127
     *
128
     * @author Donii Sergii <[email protected]>
129
     */
130 5
    protected function includeRoutes($session, $transport)
131
    {
132 5
        if (!is_dir($this->routePath) && !is_file($this->routePath)) {
133 3
            return;
134
        }
135
136 2
        if ($session instanceof ClientSession) {
137
            $this->session = $session;
138
        }
139 2
        $client = $this;
140
141
        /* @scrutinizer ignore-call */
142 2
        app()->wampRouter->setClient($client);
143
144 2
        if (is_file($this->routePath)) {
145 1
            require $this->routePath;
146 1
            app()->wampRouter->parseGroups();
147 1
            return;
148
        }
149
150 1
        if (is_dir($this->routePath)) {
151 1
            $files = scandir($this->routePath);
152
153 1
            foreach ($files as $file) {
154 1
                if ($file === '.' || $file === '..') {
155 1
                    continue;
156
                }
157
158 1
                if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
159 1
                    require $this->routePath.DIRECTORY_SEPARATOR.$file;
160
                }
161
            }
162
        }
163 1
        app()->wampRouter->parseGroups();
164 1
    }
165
}
166