NotificationsController::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Loan;
6
use App\Notifications\ExtendedDatabaseNotification;
7
use App\Notifications\FirstReminder;
8
use App\Notifications\ManualReminder;
9
use Illuminate\Http\Request;
10
use Illuminate\Http\Response;
11
use Illuminate\Support\Arr;
12
13
class NotificationsController extends Controller
14
{
15
16
    /**
17
     * Show a reminder.
18
     *
19
     * @param ExtendedDatabaseNotification $notification
20
     * @return Response
21
     */
22
    public function show(ExtendedDatabaseNotification $notification)
23
    {
24
        return response()->view('notifications.show', [
25
            'type' => $notification->humanReadableType(),
26
            'loan' => $notification->loan,
27
            'email' => Arr::get($notification->data, 'email'),
0 ignored issues
show
Bug introduced by
The property data does not seem to exist on App\Notifications\ExtendedDatabaseNotification. 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...
28
            'sent' => $notification->created_at,
29
        ]);
30
    }
31
32
    /**
33
     * Display a form to create the resource.
34
     *
35
     * @param Loan $loan
36
     * @return Response
37
     */
38
    public function create(Loan $loan)
39
    {
40
        $notification = new FirstReminder($loan);
41
        $email = $notification->email->toArray();
42
43
        return response()->view('notifications.create', array(
44
            'loan' => $loan,
45
            'email' => $email,
46
        ));
47
    }
48
49
    /**
50
     * Sends a new reminder.
51
     *
52
     * @param Loan $loan
53
     * @param Request $request
54
     * @return Response
55
     */
56
    public function send(Loan $loan, Request $request)
57
    {
58
        $loan->user->notify(new ManualReminder($loan, $request->input('subject'), $request->input('body')));
59
60
        return redirect()
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->actio... returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
61
            ->action('LoansController@getShow', $loan->id)
62
            ->with('status', 'Påminnelsen ble sendt.');
63
    }
64
}
65