App   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A findById() 0 4 1
A findByKey() 0 4 1
A findBySecret() 0 4 1
A __construct() 0 16 3
A setName() 0 6 1
A setHost() 0 6 1
A setCapacity() 0 6 1
A enableStatistics() 0 6 1
A setPath() 0 6 1
A enableClientMessages() 0 6 1
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Apps;
4
5
use BeyondCode\LaravelWebSockets\Exceptions\InvalidApp;
6
7
class App
8
{
9
    /** @var int */
10
    public $id;
11
12
    /** @var string */
13
    public $key;
14
15
    /** @var string */
16
    public $secret;
17
18
    /** @var string|null */
19
    public $name;
20
21
    /** @var string|null */
22
    public $host;
23
24
    /** @var string|null */
25
    public $path;
26
27
    /** @var int|null */
28
    public $capacity = null;
29
30
    /** @var bool */
31
    public $clientMessagesEnabled = false;
32
33
    /** @var bool */
34
    public $statisticsEnabled = true;
35
36
    public static function findById($appId)
37
    {
38
        return app(AppProvider::class)->findById($appId);
39
    }
40
41
    public static function findByKey(string $appKey): ?self
42
    {
43
        return app(AppProvider::class)->findByKey($appKey);
44
    }
45
46
    public static function findBySecret(string $appSecret): ?self
47
    {
48
        return app(AppProvider::class)->findBySecret($appSecret);
49
    }
50
51
    public function __construct($appId, string $appKey, string $appSecret)
52
    {
53
        if ($appKey === '') {
54
            throw InvalidApp::valueIsRequired('appKey', $appId);
55
        }
56
57
        if ($appSecret === '') {
58
            throw InvalidApp::valueIsRequired('appSecret', $appId);
59
        }
60
61
        $this->id = $appId;
62
63
        $this->key = $appKey;
64
65
        $this->secret = $appSecret;
66
    }
67
68
    public function setName(string $appName)
69
    {
70
        $this->name = $appName;
71
72
        return $this;
73
    }
74
75
    public function setHost(string $host)
76
    {
77
        $this->host = $host;
78
79
        return $this;
80
    }
81
82
    public function setPath(string $path)
83
    {
84
        $this->path = $path;
85
86
        return $this;
87
    }
88
89
    public function enableClientMessages(bool $enabled = true)
90
    {
91
        $this->clientMessagesEnabled = $enabled;
92
93
        return $this;
94
    }
95
96
    public function setCapacity(?int $capacity)
97
    {
98
        $this->capacity = $capacity;
99
100
        return $this;
101
    }
102
103
    public function enableStatistics(bool $enabled = true)
104
    {
105
        $this->statisticsEnabled = $enabled;
106
107
        return $this;
108
    }
109
}
110