Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 35cec91

Browse files
authored
Merge pull request #471 from beyondcode/refactor/docblocks
[2.x] Docblocks
2 parents 2074d65 + f83a669 commit 35cec91

File tree

64 files changed

+1743
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1743
-313
lines changed

docs/advanced-usage/app-providers.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ interface AppManager
2525
public function findById($appId): ?App;
2626

2727
/** @return BeyondCode\LaravelWebSockets\Apps\App */
28-
public function findByKey(string $appKey): ?App;
28+
public function findByKey($appKey): ?App;
2929

3030
/** @return BeyondCode\LaravelWebSockets\Apps\App */
31-
public function findBySecret(string $appSecret): ?App;
31+
public function findBySecret($appSecret): ?App;
3232
}
3333
```
3434

@@ -56,12 +56,12 @@ class MyCustomAppManager implements AppManager
5656
return $this->normalize(Application::findById($appId)->toArray());
5757
}
5858

59-
public function findByKey(string $appKey) : ? App
59+
public function findByKey($appKey) : ? App
6060
{
6161
return $this->normalize(Application::findByKey($appKey)->toArray());
6262
}
6363

64-
public function findBySecret(string $appSecret) : ? App
64+
public function findBySecret($appSecret) : ? App
6565
{
6666
return $this->normalize(Application::findBySecret($appSecret)->toArray());
6767
}

src/Apps/App.php

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,49 @@ class App
3636
/** @var array */
3737
public $allowedOrigins = [];
3838

39+
/**
40+
* Find the app by id.
41+
*
42+
* @param mixed $appId
43+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
44+
*/
3945
public static function findById($appId)
4046
{
4147
return app(AppManager::class)->findById($appId);
4248
}
4349

44-
public static function findByKey(string $appKey): ?self
50+
/**
51+
* Find the app by app key.
52+
*
53+
* @param mixed $appId
54+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
55+
*/
56+
public static function findByKey($appKey): ?self
4557
{
4658
return app(AppManager::class)->findByKey($appKey);
4759
}
4860

49-
public static function findBySecret(string $appSecret): ?self
61+
/**
62+
* Find the app by app secret.
63+
*
64+
* @param mixed $appId
65+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
66+
*/
67+
public static function findBySecret($appSecret): ?self
5068
{
5169
return app(AppManager::class)->findBySecret($appSecret);
5270
}
5371

54-
public function __construct($appId, string $appKey, string $appSecret)
72+
/**
73+
* Initialize the Web Socket app instance.
74+
*
75+
* @param mixed $appId
76+
* @param mixed $key
77+
* @param mixed $secret
78+
* @return void
79+
* @throws \BeyondCode\LaravelWebSockets\Exceptions\InvalidApp
80+
*/
81+
public function __construct($appId, $appKey, $appSecret)
5582
{
5683
if ($appKey === '') {
5784
throw InvalidApp::valueIsRequired('appKey', $appId);
@@ -62,54 +89,94 @@ public function __construct($appId, string $appKey, string $appSecret)
6289
}
6390

6491
$this->id = $appId;
65-
6692
$this->key = $appKey;
67-
6893
$this->secret = $appSecret;
6994
}
7095

96+
/**
97+
* Set the name of the app.
98+
*
99+
* @param string $appName
100+
* @return $this
101+
*/
71102
public function setName(string $appName)
72103
{
73104
$this->name = $appName;
74105

75106
return $this;
76107
}
77108

109+
/**
110+
* Set the app host.
111+
*
112+
* @param string $host
113+
* @return $this
114+
*/
78115
public function setHost(string $host)
79116
{
80117
$this->host = $host;
81118

82119
return $this;
83120
}
84121

122+
/**
123+
* Set path for the app.
124+
*
125+
* @param string $path
126+
* @return $this
127+
*/
85128
public function setPath(string $path)
86129
{
87130
$this->path = $path;
88131

89132
return $this;
90133
}
91134

135+
/**
136+
* Enable client messages.
137+
*
138+
* @param bool $enabled
139+
* @return $this
140+
*/
92141
public function enableClientMessages(bool $enabled = true)
93142
{
94143
$this->clientMessagesEnabled = $enabled;
95144

96145
return $this;
97146
}
98147

148+
/**
149+
* Set the maximum capacity for the app.
150+
*
151+
* @param int|null $capacity
152+
* @return $this
153+
*/
99154
public function setCapacity(?int $capacity)
100155
{
101156
$this->capacity = $capacity;
102157

103158
return $this;
104159
}
105160

161+
/**
162+
* Enable statistics for the app.
163+
*
164+
* @param bool $enabled
165+
* @return $this
166+
*/
106167
public function enableStatistics(bool $enabled = true)
107168
{
108169
$this->statisticsEnabled = $enabled;
109170

110171
return $this;
111172
}
112173

174+
/**
175+
* Add whitelisted origins.
176+
*
177+
* @param array $allowedOrigins
178+
* @return $this
179+
*/
113180
public function setAllowedOrigins(array $allowedOrigins)
114181
{
115182
$this->allowedOrigins = $allowedOrigins;

src/Apps/AppManager.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,34 @@
44

55
interface AppManager
66
{
7-
/** @return array[BeyondCode\LaravelWebSockets\Apps\App] */
7+
/**
8+
* Get all apps.
9+
*
10+
* @return array[\BeyondCode\LaravelWebSockets\Apps\App]
11+
*/
812
public function all(): array;
913

14+
/**
15+
* Get app by id.
16+
*
17+
* @param mixed $appId
18+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
19+
*/
1020
public function findById($appId): ?App;
1121

12-
public function findByKey(string $appKey): ?App;
22+
/**
23+
* Get app by app key.
24+
*
25+
* @param mixed $appKey
26+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
27+
*/
28+
public function findByKey($appKey): ?App;
1329

14-
public function findBySecret(string $appSecret): ?App;
30+
/**
31+
* Get app by secret.
32+
*
33+
* @param mixed $appSecret
34+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
35+
*/
36+
public function findBySecret($appSecret): ?App;
1537
}

src/Apps/ConfigAppManager.php

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,30 @@
22

33
namespace BeyondCode\LaravelWebSockets\Apps;
44

5-
use Illuminate\Support\Collection;
6-
75
class ConfigAppManager implements AppManager
86
{
9-
/** @var Collection */
7+
/**
8+
* The list of apps.
9+
*
10+
* @var \Illuminate\Support\Collection
11+
*/
1012
protected $apps;
1113

14+
/**
15+
* Initialize the class.
16+
*
17+
* @return void
18+
*/
1219
public function __construct()
1320
{
1421
$this->apps = collect(config('websockets.apps'));
1522
}
1623

17-
/** @return array[\BeyondCode\LaravelWebSockets\Apps\App] */
24+
/**
25+
* Get all apps.
26+
*
27+
* @return array[\BeyondCode\LaravelWebSockets\Apps\App]
28+
*/
1829
public function all(): array
1930
{
2031
return $this->apps
@@ -24,6 +35,12 @@ public function all(): array
2435
->toArray();
2536
}
2637

38+
/**
39+
* Get app by id.
40+
*
41+
* @param mixed $appId
42+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
43+
*/
2744
public function findById($appId): ?App
2845
{
2946
$appAttributes = $this
@@ -33,7 +50,13 @@ public function findById($appId): ?App
3350
return $this->instantiate($appAttributes);
3451
}
3552

36-
public function findByKey(string $appKey): ?App
53+
/**
54+
* Get app by app key.
55+
*
56+
* @param mixed $appKey
57+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
58+
*/
59+
public function findByKey($appKey): ?App
3760
{
3861
$appAttributes = $this
3962
->apps
@@ -42,7 +65,13 @@ public function findByKey(string $appKey): ?App
4265
return $this->instantiate($appAttributes);
4366
}
4467

45-
public function findBySecret(string $appSecret): ?App
68+
/**
69+
* Get app by secret.
70+
*
71+
* @param mixed $appSecret
72+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
73+
*/
74+
public function findBySecret($appSecret): ?App
4675
{
4776
$appAttributes = $this
4877
->apps
@@ -51,6 +80,12 @@ public function findBySecret(string $appSecret): ?App
5180
return $this->instantiate($appAttributes);
5281
}
5382

83+
/**
84+
* Map the app into an App instance.
85+
*
86+
* @param array|null $app
87+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
88+
*/
5489
protected function instantiate(?array $appAttributes): ?App
5590
{
5691
if (! $appAttributes) {

src/Console/CleanStatistics.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,27 @@
88

99
class CleanStatistics extends Command
1010
{
11+
/**
12+
* The name and signature of the console command.
13+
*
14+
* @var string
15+
*/
1116
protected $signature = 'websockets:clean
12-
{appId? : (optional) The app id that will be cleaned.}';
13-
17+
{appId? : (optional) The app id that will be cleaned.}
18+
';
19+
20+
/**
21+
* The console command description.
22+
*
23+
* @var string|null
24+
*/
1425
protected $description = 'Clean up old statistics from the websocket log.';
1526

27+
/**
28+
* Run the command.
29+
*
30+
* @return void
31+
*/
1632
public function handle()
1733
{
1834
$this->comment('Cleaning WebSocket Statistics...');
@@ -23,16 +39,14 @@ public function handle()
2339

2440
$cutOffDate = Carbon::now()->subDay($maxAgeInDays)->format('Y-m-d H:i:s');
2541

26-
$webSocketsStatisticsEntryModelClass = config('websockets.statistics.model');
42+
$class = config('websockets.statistics.model');
2743

28-
$amountDeleted = $webSocketsStatisticsEntryModelClass::where('created_at', '<', $cutOffDate)
44+
$amountDeleted = $class::where('created_at', '<', $cutOffDate)
2945
->when(! is_null($appId), function (Builder $query) use ($appId) {
3046
$query->where('app_id', $appId);
3147
})
3248
->delete();
3349

3450
$this->info("Deleted {$amountDeleted} record(s) from the WebSocket statistics.");
35-
36-
$this->comment('All done!');
3751
}
3852
}

src/Console/RestartWebSocketServer.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,25 @@ class RestartWebSocketServer extends Command
1010
{
1111
use InteractsWithTime;
1212

13+
/**
14+
* The name and signature of the console command.
15+
*
16+
* @var string
17+
*/
1318
protected $signature = 'websockets:restart';
1419

20+
/**
21+
* The console command description.
22+
*
23+
* @var string|null
24+
*/
1525
protected $description = 'Restart the Laravel WebSocket Server';
1626

27+
/**
28+
* Run the command.
29+
*
30+
* @return void
31+
*/
1732
public function handle()
1833
{
1934
Cache::forever('beyondcode:websockets:restart', $this->currentTime());

0 commit comments

Comments
 (0)