SendFormEntryController::__invoke()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 20
ccs 15
cts 15
cp 1
rs 9.8666
cc 4
nc 3
nop 1
crap 4
1
<?php
2
3
namespace FormEntries\Http\Controllers;
4
5
use FormEntries\Forms\Form;
6
use Illuminate\Http\Request;
7
use Illuminate\Support\Facades\Response;
8
9
class SendFormEntryController
10
{
11 3
    public function __invoke(Request $request)
12
    {
13 3
        $formClass = Form::getClassByType($request->input(config('forms-entries.routing.form_name_parameter')));
14 3
        if (is_a($formClass, Form::class, true)) {
15 2
            $formEntry = $formClass::make()->process($request);
16 2
            if ($request->expectsJson()) {
17 1
                return Response::json([
18 1
                    'message' => trans('forms-entries::messages.form_sent'),
19 1
                    'data'    => [
20 1
                        'type'     => (string) (class_exists($formEntry->type)) ? class_basename($formEntry->type) : $formEntry->type,
21 1
                        'saved'    => (bool) $formEntry->exists,
22 1
                        'notified' => (bool) $formEntry->notified_at,
23 1
                    ],
24 1
                ]);
25
            }
26
27 1
            return redirect()->back()->with('success', trans('forms-entries::messages.form_sent'));
28
        }
29
30 1
        abort(404);
31
    }
32
}
33