Completed
Pull Request — master (#14)
by Lukas
01:47
created

App::findBySecret()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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