Completed
Push — master ( 556f43...aecbfe )
by Marcel
01:49
created

App::setCapacity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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 int|null */
25
    public $capacity = null;
26
27
    /** @var bool */
28
    public $clientMessagesEnabled = false;
29
30
    /** @var bool */
31
    public $statisticsEnabled = true;
32
33
    public static function findById($appId)
34
    {
35
        return app(AppProvider::class)->findById($appId);
36
    }
37
38
    public static function findByKey(string $appKey): ?self
39
    {
40
        return app(AppProvider::class)->findByKey($appKey);
41
    }
42
43
    public static function findBySecret(string $appSecret): ?self
44
    {
45
        return app(AppProvider::class)->findBySecret($appSecret);
46
    }
47
48
    public function __construct($appId, string $appKey, string $appSecret)
49
    {
50
        if ($appKey === '') {
51
            throw InvalidApp::valueIsRequired('appKey', $appId);
52
        }
53
54
        if ($appSecret === '') {
55
            throw InvalidApp::valueIsRequired('appSecret', $appId);
56
        }
57
58
        $this->id = $appId;
59
60
        $this->key = $appKey;
61
62
        $this->secret = $appSecret;
63
    }
64
65
    public function setName(string $appName)
66
    {
67
        $this->name = $appName;
68
69
        return $this;
70
    }
71
72
    public function setHost(string $host)
73
    {
74
        $this->host = $host;
75
76
        return $this;
77
    }
78
79
    public function enableClientMessages(bool $enabled = true)
80
    {
81
        $this->clientMessagesEnabled = $enabled;
82
83
        return $this;
84
    }
85
86
    public function setCapacity(?int $capacity)
87
    {
88
        $this->capacity = $capacity;
89
90
        return $this;
91
    }
92
93
    public function enableStatistics(bool $enabled = true)
94
    {
95
        $this->statisticsEnabled = $enabled;
96
97
        return $this;
98
    }
99
}
100