NotificationRepository::userRecent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PHPHub\Repositories\Eloquent;
4
5
use PHPHub\Repositories\Eloquent\Traits\IncludeTopicTrait;
6
use PHPHub\Transformers\IncludeManager\Includable;
7
use PHPHub\Transformers\IncludeManager\IncludeManager;
8
use PHPHub\User;
9
use Prettus\Repository\Criteria\RequestCriteria;
10
use PHPHub\Repositories\NotificationRepositoryInterface;
11
use PHPHub\Notification;
12
13
/**
14
 * Class NotificationRepository.
15
 */
16
class NotificationRepository extends BaseRepository implements NotificationRepositoryInterface
17
{
18
    use IncludeTopicTrait;
19
20
    /**
21
     * 生成一条新的 Notification.
22
     *
23
     * @param $attributes
24
     *
25
     * @return Notification
26
     */
27
    public function store($attributes)
28
    {
29
        $notification = parent::create($attributes);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (create() instead of store()). Are you sure this is correct? If so, you might want to change this to $this->create().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
30
        User::whereId($notification->user_id)->increment('notification_count');
31
32
        return $notification;
33
    }
34
35
    public function includeFromUser($default_columns)
36
    {
37
        $available_include = Includable::make('from_user')
38
            ->setDefaultColumns($default_columns)
39
            ->setAllowColumns(User::$includable)
40
            ->setForeignKey('from_user_id');
41
42
        app(IncludeManager::class)->add($available_include);
43
    }
44
45
    public function includeReply($default_columns)
46
    {
47
        $available_include = Includable::make('reply')
48
            ->setDefaultColumns($default_columns)
49
            ->setAllowColumns(User::$includable)
50
            ->setForeignKey('reply_id');
51
52
        app(IncludeManager::class)->add($available_include);
53
    }
54
55
    /**
56
     * Specify Model class name.
57
     *
58
     * @return string
59
     */
60
    public function model()
61
    {
62
        return Notification::class;
63
    }
64
65
    /**
66
     * Boot up the repository, pushing criteria.
67
     */
68
    public function boot()
69
    {
70
        $this->pushCriteria(app(RequestCriteria::class));
71
    }
72
73
    /**
74
     * 用户最新的通知.
75
     *
76
     * @param $user_id
77
     *
78
     * @return $this
79
     */
80
    public function userRecent($user_id)
81
    {
82
        $this->model = $this->model
83
            ->where(compact('user_id'))
84
            ->orderBy('created_at', 'desc');
85
86
        return $this;
87
    }
88
}
89