Passed
Push — main ( 2a66c5...5262fa )
by Yaroslav
03:05
created

CheckPinController::__invoke()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 40
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 21
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 40
ccs 26
cts 26
cp 1
crap 5
rs 9.2728
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