CheckPinController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 42
ccs 26
cts 26
cp 1
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 40 5
1
<?php
2
3
namespace LinkRestrictedAccess\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Redirect;
7
use Illuminate\Support\Facades\Response;
8
use Illuminate\Validation\ValidationException;
9
use LinkRestrictedAccess\Models\RestrictedLink;
10
11
class CheckPinController extends Controller
12
{
13 2
    public function __invoke(Request $request)
14
    {
15
        /** @var RestrictedLink $restrictedLink */
16 2
        $restrictedLink = \LinkRestrictedAccess\RestrictedAccess::restrictedLinkModel()::query()
17 2
            ->where('uuid', $request->route('uuid'))
18 2
            ->firstOrFail();
19
20 2
        $request->validate([
21 2
            'pin' => [
22 2
                'required',
23 2
                'string',
24 2
                'max:100',
25 2
            ],
26 2
        ]);
27
28
        if (
29 2
            $restrictedLink->checkPin &&
0 ignored issues
show
Bug introduced by
The property checkPin does not seem to exist on LinkRestrictedAccess\Models\RestrictedLink. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
30
            (
31 2
                !$restrictedLink->pin ||
0 ignored issues
show
Bug introduced by
The property pin does not seem to exist on LinkRestrictedAccess\Models\RestrictedLink. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
32 2
                $restrictedLink->pin != $request->input('pin')
33
            )
34
35
        ) {
36 1
            throw ValidationException::withMessages([
37 1
                'pin' => __('Incorrect pin'),
38 1
            ]);
39
        }
40
41 2
        $message = __('Pin successful checked.');
42
43 2
        if ($request->expectsJson()) {
44 1
            return Response::json([
45 1
                'message' => $message,
46 1
                'data'    => [
47 1
                    'success' => true,
48 1
                ],
49 1
            ]);
50
        }
51
52 1
        return Redirect::back()->with(['message' => $message]);
53
    }
54
}
55