FetchUsersController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 18 3
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
4
5
use BeyondCode\LaravelWebSockets\WebSockets\Channels\PresenceChannel;
6
use Illuminate\Http\Request;
7
use Illuminate\Support\Collection;
8
use Symfony\Component\HttpKernel\Exception\HttpException;
9
10
class FetchUsersController extends Controller
11
{
12
    public function __invoke(Request $request)
13
    {
14
        $channel = $this->channelManager->find($request->appId, $request->channelName);
15
16
        if (is_null($channel)) {
17
            throw new HttpException(404, 'Unknown channel "'.$request->channelName.'"');
18
        }
19
20
        if (! $channel instanceof PresenceChannel) {
21
            throw new HttpException(400, 'Invalid presence channel "'.$request->channelName.'"');
22
        }
23
24
        return [
25
            'users' => Collection::make($channel->getUsers())->keys()->map(function ($userId) {
26
                return ['id' => $userId];
27
            })->values(),
28
        ];
29
    }
30
}
31