Completed
Push — master ( 7235dd...b44091 )
by Sergii
05:14
created

Client   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 68
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 12

4 Methods

Rating   Name   Duplication   Size   Complexity  
A onSessionStart() 0 3 1
A setRoutePath() 0 3 1
D includeRoutes() 0 27 9
A start() 0 4 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
    protected $routePath = null;
23
24
    protected $session;
25
26
    /**
27
     * Session start event
28
     *
29
     * @param \Thruway\ClientSession                $session
30
     * @param \Thruway\Transport\TransportInterface $transport
31
     *
32
     * @author Donii Sergii <[email protected]>
33
     */
34 3
    public function onSessionStart($session, $transport)
35
    {
36 3
        $this->includeRoutes($session, $transport);
37 3
    }
38
39 2
    public function setRoutePath($path)
40
    {
41 2
        $this->routePath = $path;
42 2
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 1
    public function start($startLoop = true)
48
    {
49 1
        app()->wampRouter->parseGroups();
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

49
        /** @scrutinizer ignore-call */ 
50
        app()->wampRouter->parseGroups();
Loading history...
50 1
        parent::start($startLoop);
51 1
    }
52
53
    /**
54
     * Include routes
55
     *
56
     * @param \Thruway\ClientSession                $session   Client session
57
     * @param \Thruway\Transport\TransportInterface $transport Transport provider
58
     *
59
     * @author Donii Sergii <[email protected]>
60
     */
61 3
    protected function includeRoutes($session, $transport)
62
    {
63 3
        if (!is_dir($this->routePath) && !is_file($this->routePath)) {
64 1
            return;
65
        }
66
67 2
        $session = $this->session = $session;
68 2
        $client = $this;
69
70
        /* @scrutinizer ignore-call */
71 2
        app()->wampRouter->setClient($client);
72
73 2
        if (is_file($this->routePath)) {
74 1
            require $this->routePath;
75 1
            return;
76
        }
77
78 1
        if (is_dir($this->routePath)) {
79 1
            $files = scandir($this->routePath);
80
81 1
            foreach ($files as $file) {
82 1
                if ($file === '.' || $file === '..') {
83 1
                    continue;
84
                }
85
86 1
                if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
87 1
                    require $this->routePath.DIRECTORY_SEPARATOR.$file;
88
                }
89
            }
90
        }
91 1
    }
92
}
93