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

Forgotten::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Http\Controllers\Api\Password;
6
7
use App\Http\Requests\Api\Password\ForgottenRequest;
8
use App\Models\User;
9
use App\Notifications\User\PasswordReset;
10
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...
11
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...
12
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...
13
use Illuminate\Contracts\Routing\ResponseFactory;
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Routing\ResponseFactory 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\Contracts\Translation\Translator;
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Translation\Translator 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
16
final class Forgotten
17
{
18
    /**
19
     * @var \Illuminate\Auth\Passwords\PasswordBrokerManager
20
     */
21
    protected $passwordBrokerManager;
22
23
    /**
24
     * @var \Illuminate\Contracts\Routing\ResponseFactory
25
     */
26
    protected $responseFactory;
27
28
    /**
29
     * @var \Illuminate\Contracts\Translation\Translator
30
     */
31
    protected $translator;
32
33
    /**
34
     * @var \Illuminate\Contracts\Notifications\Dispatcher
35
     */
36
    protected $notificationDispatcher;
37
38
    /**
39
     * Reset constructor.
40
     *
41
     * @param  \Illuminate\Auth\Passwords\PasswordBrokerManager $passwordBrokerManager
42
     * @param  \Illuminate\Contracts\Routing\ResponseFactory    $responseFactory
43
     * @param  \Illuminate\Contracts\Translation\Translator     $translator
44
     * @param  \Illuminate\Contracts\Notifications\Dispatcher   $notificationDispatcher
45
     */
46
    public function __construct(
47
        PasswordBrokerManager $passwordBrokerManager,
48
        ResponseFactory $responseFactory,
49
        Translator $translator,
50
        Dispatcher $notificationDispatcher
51
    ) {
52
        $this->passwordBrokerManager = $passwordBrokerManager;
53
        $this->responseFactory = $responseFactory;
54
        $this->translator = $translator;
55
        $this->notificationDispatcher = $notificationDispatcher;
56
    }
57
58
    /**
59
     * @param  \App\Http\Requests\Api\Password\ForgottenRequest $request
60
     * @return \Illuminate\Http\JsonResponse
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\JsonResponse 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...
61
     */
62
    public function __invoke(ForgottenRequest $request)
63
    {
64
        $user = User::query()->where('email', $request->input('email'))->first();
65
66
        if ($user instanceof User) {
67
            $this->notificationDispatcher->send($user,
68
                new PasswordReset($this->getPasswordBroker()->createToken($user))
69
            );
70
        }
71
72
        // We'll always send a successful response so that an attack can't find
73
        // what email addresses exist in the application.
74
        return $this->responseFactory->json([
75
            'message' => $this->translator->trans(PasswordBroker::RESET_LINK_SENT),
76
        ]);
77
    }
78
79
    /**
80
     * @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...
81
     */
82
    protected function getPasswordBroker(): PasswordBroker
83
    {
84
        return $this->passwordBrokerManager->broker('users');
85
    }
86
}
87