Passed
Push — master ( 62919d...1f65fa )
by Iman
04:23
created

AdminNotificationsController::getLatestJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace Crocodicstudio\Crudbooster\Modules\NotificationsModule;
4
5
use Crocodicstudio\Crudbooster\controllers\CBController;
6
7
class AdminNotificationsController extends CBController
8
{
9
    /**
10
     * AdminNotificationsController constructor.
11
     */
12
    public function __construct()
13
    {
14
        $this->table = "cms_notifications";
15
        $this->primaryKey = "id";
16
        $this->titleField = "content";
17
        $this->limit = 20;
18
        $this->orderby = ["id" => "desc"];
19
    }
20
21
    public function cbInit()
22
    {
23
        $this->setButtons();
24
        $this->makeColumns();
25
26
        $this->form = NotificationForm::makeForm();
27
    }
28
29
    private function setButtons()
30
    {
31
        $this->buttonAdd = false;
32
        $this->buttonExport = false;
33
        $this->buttonImport = false;
34
    }
35
36
    private function makeColumns()
37
    {
38
        $read_notification_url = url(cbAdminPath()).'/notifications/read';
39
40
        $this->col = [
41
            [
42
                "label" => "Content",
43
                "name" => "content",
44
                "callback_php" => '"<a href=\"'.$read_notification_url.'/$row->id\">$row->content</a>"'
45
            ],
46
            [
47
                'label' => 'Read',
48
                'name' => 'is_read',
49
                'callback_php' => '($row->is_read)?"<span class=\"label label-default\">Already Read</span>":"<span class=\"label label-danger\">NEW</span>"',
50
            ],
51
        ];
52
    }
53
54
    public function hookQueryIndex($query)
55
    {
56
        $query->where('cms_users_id', auth('cbAdmin')->id());
57
    }
58
59
    public function getLatestJson()
60
    {
61
        $rows = $this->table()
62
            ->where('cms_users_id', 0)
63
            ->orWhere('cms_users_id', auth('cbAdmin')->id())
64
            ->orderby('id', 'desc')
65
            ->where('is_read', 0)
66
            ->whereNull('deleted_at')
67
            ->take(25)
68
            ->get();
69
70
        return response()->json(['items' => $rows, 'total' => count($rows)]);
0 ignored issues
show
Bug introduced by
The method json() does not exist on Symfony\Component\HttpFoundation\Response. It seems like you code against a sub-type of Symfony\Component\HttpFoundation\Response such as Illuminate\Http\Response or Illuminate\Http\JsonResponse or Illuminate\Http\RedirectResponse. ( Ignorable by Annotation )

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

70
        return response()->/** @scrutinizer ignore-call */ json(['items' => $rows, 'total' => count($rows)]);
Loading history...
Bug introduced by
Are you sure the usage of response()->json(array('...otal' => count($rows))) targeting ImanGhafoori\Terminator\Responder::json() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
71
    }
72
73
    public function getRead($id)
74
    {
75
        $this->findRow($id)->update(['is_read' => 1]);
76
        $row = $this->findRow($id)->first();
77
78
        return redirect($row->url);
79
    }
80
}