SubscribeController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A mailing_list() 0 5 1
A preUnSubscribe() 0 7 1
A unSubscribe() 0 10 1
A subscribe() 0 10 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\MailingList;
6
use App\Models\Subscription;
7
use App\Http\Requests\SubscribeRequest;
8
9
class SubscribeController extends Controller
10
{
11
    /**
12
     * @param MailingList $list
13
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
14
     */
15
    public function mailing_list(MailingList $list)
16
    {
17
        abort_unless($list->public, 404);
0 ignored issues
show
Bug introduced by
$list->public of type integer is incompatible with the type boolean expected by parameter $boolean of abort_unless(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

17
        abort_unless(/** @scrutinizer ignore-type */ $list->public, 404);
Loading history...
18
19
        return view('subscribe.list', compact('list'));
20
    }
21
22
    /**
23
     * @param SubscribeRequest $request
24
     * @param MailingList $list
25
     * @return \Illuminate\Http\RedirectResponse
26
     */
27
    public function subscribe(SubscribeRequest $request, MailingList $list)
28
    {
29
        $subscription = $list->subscriptions()->create($request->all());
0 ignored issues
show
Unused Code introduced by
The assignment to $subscription is dead and can be removed.
Loading history...
30
31
        notify()->flash($list->name, 'success', [
32
            'timer' => 2000,
33
            'text' => trans('subscriptions.subscribe.success'),
34
        ]);
35
36
        return redirect()->back();
37
    }
38
39
    /**
40
     * @param $email
41
     * @param $unSubscribe
42
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
43
     */
44
    public function preUnSubscribe($email, $unSubscribe)
45
    {
46
        $subscription = Subscription::whereEmail($email)->whereUnsubscribe($unSubscribe)->first();
47
48
        abort_unless($subscription, 404);
0 ignored issues
show
Bug introduced by
It seems like $subscription can also be of type App\Models\Subscription; however, parameter $boolean of abort_unless() does only seem to accept boolean, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
        abort_unless(/** @scrutinizer ignore-type */ $subscription, 404);
Loading history...
49
50
        return view('subscriptions.unsubscribe', compact('subscription'));
51
    }
52
53
    /**
54
     * @param Subscription $subscription
55
     * @return \Illuminate\Http\RedirectResponse
56
     */
57
    public function unSubscribe(Subscription $subscription)
58
    {
59
        $subscription->delete();
60
61
        notify()->flash(trans('general.woohoo'), 'success', [
0 ignored issues
show
Bug introduced by
It seems like trans('general.woohoo') can also be of type array; however, parameter $message of Codecourse\Notify\Notifier::flash() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
        notify()->flash(/** @scrutinizer ignore-type */ trans('general.woohoo'), 'success', [
Loading history...
62
            'timer' => 3500,
63
            'text' => trans('subscriptions.unsubscribe.success'),
64
        ]);
65
66
        return redirect()->route('index');
67
    }
68
}
69