Completed
Push — master ( eaebda...a73821 )
by Manel
02:56
created

Activity   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 38
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A subject() 0 4 1
A feed() 0 11 1
1
<?php
2
3
namespace Scool\EnrollmentMobile\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
/**
8
 * Class Activity
9
 * @package Scool\EnrollmentMobile
10
 */
11
class Activity extends Model
12
{
13
    /**
14
     * Don't auto-apply mass assignment protection.
15
     *
16
     * @var array
17
     */
18
    protected $guarded = [];
19
20
    /**
21
     * Fetch the associated subject for the activity.
22
     *
23
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
24
     */
25
    public function subject()
26
    {
27
        return $this->morphTo();
28
    }
29
30
    /**
31
     * Fetch an activity feed for the given user.
32
     *
33
     * @param  User $user
34
     * @param  int  $take
35
     * @return \Illuminate\Database\Eloquent\Collection;
0 ignored issues
show
Documentation introduced by
The doc-type \Illuminate\Database\Eloquent\Collection; could not be parsed: Expected "|" or "end of type", but got ";" at position 40. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
36
     */
37
    public static function feed($user, $take = 50)
38
    {
39
        return static::where('user_id', $user->id)
40
            ->latest()
41
            ->with('subject')
42
            ->take($take)
43
            ->get()
44
            ->groupBy(function ($activity) {
45
                return $activity->created_at->format('Y-m-d');
46
            });
47
    }
48
}
49