Completed
Push — master ( 4dc059...6205c3 )
by Sergii
19:21 queued 11:54
created

Client   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Test Coverage

Coverage 85%

Importance

Changes 0
Metric Value
dl 0
loc 141
ccs 34
cts 40
cp 0.85
rs 10
c 0
b 0
f 0
wmc 17

8 Methods

Rating   Name   Duplication   Size   Complexity  
D includeRoutes() 0 32 9
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\Peer\Client as PeerClient;
13
14
/**
15
 * Class Client
16
 * Client class.
17
 *
18
 * @author Donii Sergii <[email protected]>
19
 */
20
class Client extends PeerClient
21
{
22
    /**
23
     * Path to WAMP routes
24
     *
25
     * @var string|null
26
     *
27
     * @author Donii Sergii <[email protected]>
28
     */
29
    protected $routePath = null;
30
31
    /**
32
     * Retry connection on close or no
33
     *
34
     * @var bool
35
     *
36
     * @author Donii Sergii <[email protected]>
37
     */
38
    protected $connectionRetry = true;
39
40
    /**
41
     * Realm
42
     *
43
     * @var string
44
     *
45
     * @author Donii Sergii <[email protected]>
46
     */
47
    protected $realm;
48
49
    /**
50
     * Session start event
51
     *
52
     * @param \Thruway\ClientSession                $session
53
     * @param \Thruway\Transport\TransportInterface $transport
54
     *
55
     * @author Donii Sergii <[email protected]>
56
     */
57 5
    public function onSessionStart($session, $transport)
58
    {
59 5
        $this->includeRoutes($session, $transport);
60 5
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 3
    public function start($startLoop = true)
66
    {
67 3
        parent::start($startLoop);
68 3
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73 2
    public function onClose($reason, $retry = true)
74
    {
75 2
        $this->connectionRetry = $retry;
76
77 2
        parent::onClose($reason);
78 2
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 2
    public function retryConnection()
84
    {
85 2
        if (!$this->connectionRetry) {
86 2
            return;
87
        }
88
89
        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...
90
    }
91
92 2
    public function setRoutePath($path)
93
    {
94 2
        $this->routePath = $path;
95 2
    }
96
97
    /**
98
     * Set attribute connectionRetry
99
     *
100
     * @return bool
101
     *
102
     * @author Donii Sergii <[email protected]>
103
     */
104
    public function isConnectionRetry(): bool
105
    {
106
        return $this->connectionRetry;
107
    }
108
109
    /**
110
     * Set connection retry
111
     *
112
     * @param bool $connectionRetry
113
     *
114
     * @author Donii Sergii <[email protected]>
115
     */
116
    public function setConnectionRetry(bool $connectionRetry)
117
    {
118
        $this->connectionRetry = $connectionRetry;
119
    }
120
121
    /**
122
     * Include routes
123
     *
124
     * @param \Thruway\ClientSession                $session   Client session
125
     * @param \Thruway\Transport\TransportInterface $transport Transport provider
126
     *
127
     * @author Donii Sergii <[email protected]>
128
     */
129 5
    protected function includeRoutes($session, $transport)
130
    {
131 5
        if (!is_dir($this->routePath) && !is_file($this->routePath)) {
132 3
            return;
133
        }
134
135 2
        $session = $this->session = $session;
136 2
        $client = $this;
137
138
        /* @scrutinizer ignore-call */
139 2
        app()->wampRouter->setClient($client);
140
141 2
        if (is_file($this->routePath)) {
142 1
            require $this->routePath;
143 1
            app()->wampRouter->parseGroups();
144 1
            return;
145
        }
146
147 1
        if (is_dir($this->routePath)) {
148 1
            $files = scandir($this->routePath);
149
150 1
            foreach ($files as $file) {
151 1
                if ($file === '.' || $file === '..') {
152 1
                    continue;
153
                }
154
155 1
                if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
156 1
                    require $this->routePath.DIRECTORY_SEPARATOR.$file;
157
                }
158
            }
159
        }
160 1
        app()->wampRouter->parseGroups();
161 1
    }
162
}
163