SendFormEntryController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 2
b 0
f 0
dl 0
loc 22
ccs 15
cts 15
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 20 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