App::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 5
rs 10
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Apps;
4
5
use BeyondCode\LaravelWebSockets\Contracts\AppManager;
6
7
class App
8
{
9
    /** @var string|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
    /** @var array */
37
    public $allowedOrigins = [];
38
39
    /**
40
     * Find the app by id.
41
     *
42
     * @param  string|int  $appId
43
     * @return \BeyondCode\LaravelWebSockets\Apps\App|null
44
     */
45
    public static function findById($appId)
46
    {
47
        return app(AppManager::class)->findById($appId);
48
    }
49
50
    /**
51
     * Find the app by app key.
52
     *
53
     * @param  string  $appKey
54
     * @return \BeyondCode\LaravelWebSockets\Apps\App|null
55
     */
56
    public static function findByKey($appKey): ?self
57
    {
58
        return app(AppManager::class)->findByKey($appKey);
59
    }
60
61
    /**
62
     * Find the app by app secret.
63
     *
64
     * @param  string  $appSecret
65
     * @return \BeyondCode\LaravelWebSockets\Apps\App|null
66
     */
67
    public static function findBySecret($appSecret): ?self
68
    {
69
        return app(AppManager::class)->findBySecret($appSecret);
70
    }
71
72
    /**
73
     * Initialize the Web Socket app instance.
74
     *
75
     * @param  string|int  $appId
76
     * @param  string  $key
77
     * @param  string  $secret
78
     * @return void
79
     */
80
    public function __construct($appId, $appKey, $appSecret)
81
    {
82
        $this->id = $appId;
83
        $this->key = $appKey;
84
        $this->secret = $appSecret;
85
    }
86
87
    /**
88
     * Set the name of the app.
89
     *
90
     * @param  string  $appName
91
     * @return $this
92
     */
93
    public function setName(string $appName)
94
    {
95
        $this->name = $appName;
96
97
        return $this;
98
    }
99
100
    /**
101
     * Set the app host.
102
     *
103
     * @param  string  $host
104
     * @return $this
105
     */
106
    public function setHost(string $host)
107
    {
108
        $this->host = $host;
109
110
        return $this;
111
    }
112
113
    /**
114
     * Set path for the app.
115
     *
116
     * @param  string  $path
117
     * @return $this
118
     */
119
    public function setPath(string $path)
120
    {
121
        $this->path = $path;
122
123
        return $this;
124
    }
125
126
    /**
127
     * Enable client messages.
128
     *
129
     * @param  bool  $enabled
130
     * @return $this
131
     */
132
    public function enableClientMessages(bool $enabled = true)
133
    {
134
        $this->clientMessagesEnabled = $enabled;
135
136
        return $this;
137
    }
138
139
    /**
140
     * Set the maximum capacity for the app.
141
     *
142
     * @param  int|null  $capacity
143
     * @return $this
144
     */
145
    public function setCapacity(?int $capacity)
146
    {
147
        $this->capacity = $capacity;
148
149
        return $this;
150
    }
151
152
    /**
153
     * Enable statistics for the app.
154
     *
155
     * @param  bool  $enabled
156
     * @return $this
157
     */
158
    public function enableStatistics(bool $enabled = true)
159
    {
160
        $this->statisticsEnabled = $enabled;
161
162
        return $this;
163
    }
164
165
    /**
166
     * Add whitelisted origins.
167
     *
168
     * @param  array  $allowedOrigins
169
     * @return $this
170
     */
171
    public function setAllowedOrigins(array $allowedOrigins)
172
    {
173
        $this->allowedOrigins = $allowedOrigins;
174
175
        return $this;
176
    }
177
}
178