NotificationController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 57
rs 10
c 1
b 0
f 1
wmc 3
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A index() 0 16 1
A unreadMessagesCount() 0 6 1
1
<?php
2
3
namespace PHPHub\Http\ApiControllers;
4
5
use Auth;
6
use PHPHub\Repositories\NotificationRepositoryInterface;
7
use PHPHub\Repositories\UserRepositoryInterface;
8
use PHPHub\Transformers\NotificationTransformer;
9
10
class NotificationController extends Controller
11
{
12
    /**
13
     * @var NotificationRepositoryInterface
14
     */
15
    private $notifications;
16
    /**
17
     * @var UserRepositoryInterface
18
     */
19
    private $users;
20
21
    /**
22
     * NotificationController constructor.
23
     *
24
     * @param NotificationRepositoryInterface $repository
25
     * @param UserRepositoryInterface         $user_repository
26
     */
27
    public function __construct(NotificationRepositoryInterface $repository, UserRepositoryInterface $user_repository)
28
    {
29
        $this->notifications = $repository;
30
        $this->users = $user_repository;
31
    }
32
33
    /**
34
     * 获取当前用户的通知消息.
35
     *
36
     * @return \Illuminate\Http\Response
37
     */
38
    public function index()
39
    {
40
        $this->notifications->addAvailableInclude('from_user', ['name', 'avatar']);
41
        $this->notifications->addAvailableInclude('reply', ['created_at']);
42
        $this->notifications->addAvailableInclude('topic', ['title']);
43
44
        $data = $this->notifications
45
            ->userRecent(Auth::id())
46
            ->autoWith()
47
            ->autoWithRootColumns(['id', 'type', 'body', 'topic_id', 'reply_id', 'created_at'])
48
            ->paginate(per_page());
49
50
        $this->users->setUnreadMessagesCount(Auth::id(), 0);
51
52
        return $this->response()->paginator($data, new NotificationTransformer());
53
    }
54
55
    /**
56
     * 获取当前用户的未读消息数.
57
     *
58
     * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
59
     */
60
    public function unreadMessagesCount()
61
    {
62
        $count = $this->users->getUnreadMessagesCount();
63
64
        return response(compact('count'));
0 ignored issues
show
Documentation introduced by
compact('count') is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65
    }
66
}
67