WebSocketController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 57
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getClient() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: shanmaseen
5
 * Date: 24/03/19
6
 * Time: 07:43 م
7
 */
8
9
namespace Shamaseen\Laravel\Ratchet\Controllers;
10
11
12
use Illuminate\Support\Collection;
13
use Ratchet\ConnectionInterface;
14
use Shamaseen\Laravel\Ratchet\Objects\Clients\Client;
15
use Shamaseen\Laravel\Ratchet\Objects\Rooms\Room;
16
use Shamaseen\Laravel\Ratchet\Receiver;
17
use Shamaseen\Laravel\Ratchet\Traits\Validation;
18
use Shamaseen\Laravel\Ratchet\Traits\WebSocketMessagesManager;
19
20
/**
21
 * Class WebSocketController
22
 * @package App\WebSockets\Controllers
23
 */
24
class WebSocketController
25
{
26
    use WebSocketMessagesManager,Validation;
27
28
    /**
29
     * @var Client[]
30
     */
31
    public $clients;
32
33
    /**
34
     * Auth to resourceId mapper
35
     * @var array
36
     */
37
    public $userAuthSocketMapper;
38
39
    /**
40
     * Ratchet ConnectionInterface
41
     * @var ConnectionInterface
42
     */
43
    public $conn;
44
45
    /**
46
     * The main receiver of websocket event, here we can change property for all connection.
47
     * @var Receiver
48
     */
49
    public $receiver;
50
51
    /**
52
     * The rooms array
53
     * @var Room[]
54
     */
55
    public $rooms;
56
57
    /**
58
     * @var Collection
59
     */
60
    public $request;
61
62
    /**
63
     * @var array
64
     */
65
    public $route;
66
67
    public function __construct()
68
    {
69
70
    }
71
72
    /**
73
     * @desc return the client class
74
     * @return Client
75
     */
76
    function getClient()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
77
    {
78
        return $this->clients[$this->conn->resourceId];
0 ignored issues
show
Bug introduced by
Accessing resourceId on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
79
    }
80
}
81