SearchesController::unsubscribe()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php namespace JobApis\JobsToMail\Http\Controllers;
2
3
use Illuminate\Foundation\Bus\DispatchesJobs;
4
use Illuminate\Http\Request;
5
use Illuminate\Routing\Controller as BaseController;
6
use Illuminate\Foundation\Validation\ValidatesRequests;
7
use Illuminate\Support\Facades\URL;
8
use JobApis\JobsToMail\Jobs\Searches\Delete;
9
use JobApis\JobsToMail\Jobs\Searches\GetUserSearches;
10
11
class SearchesController extends BaseController
12
{
13
    use DispatchesJobs, ValidatesRequests;
14
15
    /**
16
     * View a user's searches
17
     */
18
    public function index(Request $request, $userId = null)
19
    {
20
        // Get the searches for this user (or specified in ID)
21
        $results = $this->dispatchNow(
22
            new GetUserSearches(
23
                $userId ?: $request->session()->get('user.id')
24
            )
25
        );
26
27
        if (!$results->isEmpty()) {
28
            return view('searches.index', ['searches' => $results]);
29
        }
30
31
        $request->session()->flash('alert-danger', 'You currently have no active searches. Try adding one.');
0 ignored issues
show
Bug introduced by
The method flash() does not seem to exist on object<Symfony\Component...ssion\SessionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
33
        return redirect('/');
34
    }
35
36
    /**
37
     * Unsubscribe from single search
38
     */
39
    public function unsubscribe(Request $request, $searchId)
40
    {
41
        $message = $this->dispatchNow(new Delete($searchId));
42
43
        $request->session()->flash($message->type, $message->message);
0 ignored issues
show
Bug introduced by
The method flash() does not seem to exist on object<Symfony\Component...ssion\SessionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
45
        return redirect(URL::previous('/'));
46
    }
47
}
48