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

Commit 0b412cd

Browse files
committed
added docblocks
1 parent 3b49bcd commit 0b412cd

File tree

64 files changed

+1743
-311
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
-311
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,28 @@
66

77
class ConfigAppManager implements AppManager
88
{
9-
/** @var Collection */
9+
/**
10+
* The list of apps.
11+
*
12+
* @var \Illuminate\Support\Collection
13+
*/
1014
protected $apps;
1115

16+
/**
17+
* Initialize the class.
18+
*
19+
* @return void
20+
*/
1221
public function __construct()
1322
{
1423
$this->apps = collect(config('websockets.apps'));
1524
}
1625

17-
/** @return array[\BeyondCode\LaravelWebSockets\Apps\App] */
26+
/**
27+
* Get all apps.
28+
*
29+
* @return array[\BeyondCode\LaravelWebSockets\Apps\App]
30+
*/
1831
public function all(): array
1932
{
2033
return $this->apps
@@ -24,6 +37,12 @@ public function all(): array
2437
->toArray();
2538
}
2639

40+
/**
41+
* Get app by id.
42+
*
43+
* @param mixed $appId
44+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
45+
*/
2746
public function findById($appId): ?App
2847
{
2948
$appAttributes = $this
@@ -33,7 +52,13 @@ public function findById($appId): ?App
3352
return $this->instantiate($appAttributes);
3453
}
3554

36-
public function findByKey(string $appKey): ?App
55+
/**
56+
* Get app by app key.
57+
*
58+
* @param mixed $appKey
59+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
60+
*/
61+
public function findByKey($appKey): ?App
3762
{
3863
$appAttributes = $this
3964
->apps
@@ -42,7 +67,13 @@ public function findByKey(string $appKey): ?App
4267
return $this->instantiate($appAttributes);
4368
}
4469

45-
public function findBySecret(string $appSecret): ?App
70+
/**
71+
* Get app by secret.
72+
*
73+
* @param mixed $appSecret
74+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
75+
*/
76+
public function findBySecret($appSecret): ?App
4677
{
4778
$appAttributes = $this
4879
->apps
@@ -51,6 +82,12 @@ public function findBySecret(string $appSecret): ?App
5182
return $this->instantiate($appAttributes);
5283
}
5384

85+
/**
86+
* Map the app into an App instance.
87+
*
88+
* @param array|null $app
89+
* @return \BeyondCode\LaravelWebSockets\Apps\App|null
90+
*/
5491
protected function instantiate(?array $appAttributes): ?App
5592
{
5693
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)