Completed
Push — develop ( 07d6ba...5ee32e )
by Tony
17:01
created

NotificationController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Dingo\Api\Http;
6
use Dingo\Api\Routing\Helpers;
7
use Illuminate\Http\Request;
8
9
class NotificationController extends Controller
10
{
11
    use Helpers;
12
13
    /**
14
     * Constructor
15
     */
16 1
    public function __construct()
17
    {
18 1
        $this->middleware('auth');
19 1
    }
20
21
    /**
22
     * Display a listing of the resource.
23
     *
24
     * @param null $type
25
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
26
     */
27 1
    public function index($type = null)
28
    {
29
30 1
        $notifications = $this->api->be(auth()->user())->get('/api/notifications/'.$type);
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

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...
31 1
        if ($type === 'archive') {
32 1
            $page = '';
33 1
            $button = 'Notifications';
34 1
            $bg = 'maroon';
35 1
        }
36
        else {
37 1
            $page = 'archive';
38 1
            $button = 'Archive';
39 1
            $bg = 'blue';
40
        }
41
42 1
        return view('notifications.list', compact(['notifications', 'page', 'button', 'bg', "type"]));
43
    }
44
45
    /**
46
     * Update a notifications status.
47
     *
48
     * @param $id
49
     * @param $action
50
     * @return \Illuminate\Http\JsonResponse
51
     */
52
    public function update($id, $action)
53
    {
54
        return response()->json($this->api->be(auth()->user())->patch('/api/notifications/'.$id.'/'.$action));
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

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...
55
    }
56
57
    /**
58
     * Create a new notification
59
     *
60
     * @param Request $request
61
     * @return \Illuminate\Http\JsonResponse
62
     */
63
    public function create(Request $request)
64
    {
65
        $this->validate($request, [
66
            'title' => 'required|unique:notifications|max:255',
67
            'body'  => 'required',
68
        ]);
69
        return response()->json($this->api->be(auth()->user())->put('/api/notifications', ['title' => $request->title, 'body' => $request->body]));
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

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...
70
    }
71
72
}
73