AuthenticateDashboard   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 28
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 1
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
4
5
use BeyondCode\LaravelWebSockets\Apps\App;
6
use BeyondCode\LaravelWebSockets\Concerns\PushesToPusher;
7
use Illuminate\Broadcasting\Broadcasters\PusherBroadcaster;
8
use Illuminate\Http\Request;
9
10
class AuthenticateDashboard
11
{
12
    use PushesToPusher;
13
14
    /**
15
     * Find the app by using the header
16
     * and then reconstruct the PusherBroadcaster
17
     * using our own app selection.
18
     *
19
     * @param  \Illuminate\Http\Request  $request
20
     * @return \Illuminate\Http\Response
21
     */
22
    public function __invoke(Request $request)
23
    {
24
        $app = App::findById($request->header('X-App-Id'));
0 ignored issues
show
Bug introduced by
It seems like $request->header('X-App-Id') can also be of type array; however, parameter $appId of BeyondCode\LaravelWebSockets\Apps\App::findById() does only seem to accept integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

24
        $app = App::findById(/** @scrutinizer ignore-type */ $request->header('X-App-Id'));
Loading history...
25
26
        $broadcaster = $this->getPusherBroadcaster([
27
            'key' => $app->key,
28
            'secret' => $app->secret,
29
            'id' =>$app->id,
30
        ]);
31
32
        /*
33
         * Since the dashboard itself is already secured by the
34
         * Authorize middleware, we can trust all channel
35
         * authentication requests in here.
36
         */
37
        return $broadcaster->validAuthenticationResponse($request, []);
38
    }
39
}
40