Completed
Push — master ( 744b64...0d51b0 )
by Tony
8s
created

NotificationController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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
     * Display a listing of the resource.
15
     *
16 1
     * @param null $type
17
     * @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...
18 1
     */
19 1
    public function index($type = null)
20
    {
21
22
        $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...
23
        if ($type === 'archive') {
24
            $page = '';
25
            $button = 'Notifications';
26
            $bg = 'maroon';
27 1
        }
28
        else {
29
            $page = 'archive';
30 1
            $button = 'Archive';
31 1
            $bg = 'blue';
32 1
        }
33 1
34 1
        return view('notifications.list', compact(['notifications', 'page', 'button', 'bg', "type"]));
35 1
    }
36
37 1
    /**
38 1
     * Update a notifications status.
39 1
     *
40
     * @param $id
41
     * @param $action
42 1
     * @return \Illuminate\Http\JsonResponse
43
     */
44
    public function update($id, $action)
45
    {
46
        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...
47
    }
48
49
    /**
50
     * Create a new notification
51
     *
52
     * @param Request $request
53
     * @return \Illuminate\Http\JsonResponse
54
     */
55
    public function create(Request $request)
56
    {
57
        $this->validate($request, [
58
            'title' => 'required|unique:notifications|max:255',
59
            'body'  => 'required',
60
        ]);
61
        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...
62
    }
63
64
}
65