PrivateUserChannelParameters::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1.048

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 19
ccs 7
cts 11
cp 0.6364
rs 9.8666
cc 1
nc 1
nop 0
crap 1.048
1
<?php
2
3
namespace MallardDuck\DynamicEcho\Channels;
4
5
use App\Models\User;
0 ignored issues
show
Bug introduced by
The type App\Models\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Http\Request;
7
use MallardDuck\DynamicEcho\Contracts\HasDynamicChannelFormula;
8
9
/**
10
 * Class PrivateChannelParameters
11
 *
12
 * @mixin AbstractChannelParameters
13
 */
14
final class PrivateUserChannelParameters extends AbstractChannelParameters
15
{
16 1
    public function __construct()
17
    {
18 1
        $this->channelType = \Illuminate\Broadcasting\PrivateChannel::class;
19 1
        $this->channelAuthName = 'App.Models.User.{userId}';
20 1
        $this->channelAuthCallback = static function (User $user, $userId) {
21
            return (int) $user->id === (int) $userId;
22
        };
23 1
        $this->channelContextBindingCallback = static function (Request $request) {
24
            return [
25
                'userId' => $request->user()->id
26
            ];
27
        };
28 1
        $this->eventChannelIdentifierBindingCallback = static function (HasDynamicChannelFormula $event) {
29
            $self = $event;
30
            return [
31
                'userId' => $self->userId,
0 ignored issues
show
Bug introduced by
Accessing userId on the interface MallardDuck\DynamicEcho\...asDynamicChannelFormula suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
32
            ];
33
        };
34 1
        parent::__construct();
35 1
    }
36
}
37