Completed
Pull Request — master (#17)
by ARCANEDEV
04:55
created

UserPresenter::getFormattedLastActivityAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php namespace Arcanesoft\Auth\Models\Presenters;
2
3
/**
4
 * Class     UserPresenter
5
 *
6
 * @package  Arcanesoft\Auth\Models\Observers
7
 * @author   ARCANEDEV <[email protected]>
8
 *
9
 * @property  string          full_name
10
 * @property  string          since_date
11
 * @property  string          gravatar
12
 * @property  string          formatted_last_activity
13
 *
14
 * @property  \Carbon\Carbon  last_activity
15
 * @property  \Carbon\Carbon  created_at
16
 */
17
trait UserPresenter
18
{
19
    /* ------------------------------------------------------------------------------------------------
20
     |  Traits
21
     | ------------------------------------------------------------------------------------------------
22
     */
23
    use HasherTrait;
24
25
    /* ------------------------------------------------------------------------------------------------
26
     |  Getters & Setters
27
     | ------------------------------------------------------------------------------------------------
28
     */
29
    /**
30
     * Get the `full_name` attribute or use the username if empty.
31
     *
32
     * @return string
33
     */
34
    public function getFullNameAttribute()
35
    {
36
        $fullName = trim("{$this->first_name} {$this->last_name}");
0 ignored issues
show
Bug introduced by
The property first_name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property last_name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
37
38
        return empty($fullName) ? $this->username : $fullName;
0 ignored issues
show
Bug introduced by
The property username does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
39
    }
40
41
    /**
42
     * Get the `since_date` attribute (translated).
43
     *
44
     * @return string
45
     */
46
    public function getSinceDateAttribute()
47
    {
48
        return trans('auth::users.since', [
49
            'date' => $this->created_at->toFormattedDateString()
50
        ]);
51
    }
52
53
    /**
54
     * Get the `gravatar` attribute.
55
     *
56
     * @return string
57
     */
58
    public function getGravatarAttribute()
59
    {
60
        return gravatar()
61
            ->setDefaultImage('mm')->setSize(160)
62
            ->src($this->email);
0 ignored issues
show
Bug introduced by
The property email does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
63
    }
64
65
    /**
66
     * Get the `formatted_last_activity` attribute.
67
     *
68
     * @return string
69
     */
70
    public function getFormattedLastActivityAttribute()
71
    {
72
        return is_null($this->last_activity)
73
            ? trans('auth::users.no-activity')
74
            : $this->last_activity->diffForHumans();
75
    }
76
}
77