Issues (18)

src/Http/Controllers/GdprController.php (3 issues)

1
<?php
2
3
namespace Soved\Laravel\Gdpr\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
0 ignored issues
show
The type App\Http\Controllers\Controller 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\Support\Facades\Auth;
7
use Illuminate\Foundation\Http\FormRequest;
8
use Soved\Laravel\Gdpr\Events\GdprDownloaded;
9
use Soved\Laravel\Gdpr\Http\Requests\GdprDownload;
10
11
class GdprController extends Controller
12
{
13
    /**
14
     * Download the GDPR compliant data portability JSON file.
15
     *
16
     * @return \Illuminate\Http\JsonResponse
17
     */
18
    public function download(GdprDownload $request)
19
    {
20
        if (! $this->validateRequest($request)) {
21
            return $this->sendFailedLoginResponse();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->sendFailedLoginResponse() returns the type void which is incompatible with the documented return type Illuminate\Http\JsonResponse.
Loading history...
Are you sure the usage of $this->sendFailedLoginResponse() targeting Soved\Laravel\Gdpr\Http\...ndFailedLoginResponse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
22
        }
23
24
        $data = $request->user()->portable();
25
26
        event(new GdprDownloaded($request->user()));
27
28
        // Backward compatible streamDownload() behavior
29
30
        return response()->json(
31
            $data,
32
            200,
33
            [
34
                'Content-Disposition' => 'attachment; filename="user.json"',
35
            ]
36
        );
37
    }
38
39
    /**
40
     * Validate the request.
41
     *
42
     * @return bool
43
     */
44
    protected function validateRequest(FormRequest $request)
45
    {
46
        if (config('gdpr.re-authenticate', true)) {
47
            return $this->hasValidCredentials($request);
48
        }
49
50
        return Auth::check();
51
    }
52
53
    /**
54
     * Validate a user's credentials.
55
     *
56
     * @return bool
57
     */
58
    protected function hasValidCredentials(FormRequest $request)
59
    {
60
        $credentials = [
61
            $request->user()->getAuthIdentifierName() => $request->user()->getAuthIdentifier(),
62
            'password'                                => $request->input('password'),
63
        ];
64
65
        return Auth::validate($credentials);
66
    }
67
68
    /**
69
     * Get the failed login response.
70
     *
71
     * @return void
72
     */
73
    protected function sendFailedLoginResponse()
74
    {
75
        abort(403, 'Unauthorized.');
76
    }
77
}
78