Test Failed
Push — master ( ffc71e...1a0a2f )
by Koen
03:32
created

Store::getPasswordBroker()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Http\Controllers\Api\User;
6
7
use App\Http\Requests\Api\User\StoreRequest;
8
use App\Http\Resources\Api\UserResource;
9
use App\Models\User;
10
use App\Notifications\User\Invitation;
11
use Illuminate\Auth\Passwords\PasswordBrokerManager;
0 ignored issues
show
Bug introduced by
The type Illuminate\Auth\Passwords\PasswordBrokerManager 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...
12
use Illuminate\Contracts\Auth\PasswordBroker;
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Auth\PasswordBroker 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...
13
use Illuminate\Contracts\Notifications\Dispatcher;
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Notifications\Dispatcher 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...
14
use Illuminate\Support\Arr;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Arr 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...
15
use Illuminate\Support\Str;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Str 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...
16
17
final class Store
18
{
19
    /**
20
     * @var \Illuminate\Contracts\Notifications\Dispatcher
21
     */
22
    protected $notificationDispatcher;
23
24
    /**
25
     * @var \Illuminate\Auth\Passwords\PasswordBrokerManager
26
     */
27
    protected $passwordBrokerManager;
28
29
    /**
30
     * Store constructor.
31
     *
32
     * @param  \Illuminate\Contracts\Notifications\Dispatcher   $notificationDispatcher
33
     * @param  \Illuminate\Auth\Passwords\PasswordBrokerManager $passwordBrokerManager
34
     */
35
    public function __construct(Dispatcher $notificationDispatcher, PasswordBrokerManager $passwordBrokerManager)
36
    {
37
        $this->notificationDispatcher = $notificationDispatcher;
38
        $this->passwordBrokerManager = $passwordBrokerManager;
39
    }
40
41
    /**
42
     * @param  \App\Http\Requests\Api\User\StoreRequest $request
43
     * @return \App\Http\Resources\Api\UserResource
44
     */
45
    public function __invoke(StoreRequest $request)
46
    {
47
        $attributes = $request->validated();
48
49
        // Don't need an actual password yet as we're going to send an invite.
50
        Arr::set($attributes, 'password', Str::random(64));
51
52
        /** @var User $user */
53
        $user = User::query()->create($attributes);
54
55
        $this->notificationDispatcher->send($user,
56
            new Invitation($this->getPasswordBroker()->createToken($user))
57
        );
58
59
        return new UserResource($user);
60
    }
61
62
    /**
63
     * @return \Illuminate\Contracts\Auth\PasswordBroker|\Illuminate\Auth\Passwords\PasswordBroker
0 ignored issues
show
Bug introduced by
The type Illuminate\Auth\Passwords\PasswordBroker 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...
64
     */
65
    protected function getPasswordBroker(): PasswordBroker
66
    {
67
        return $this->passwordBrokerManager->broker('user-invitations');
68
    }
69
}
70