UserPresenter::getLastActivityDateAttribute()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 14
rs 9.2
1
<?php
2
3
namespace App\Services\Auth;
4
5
trait UserPresenter
6
{
7
    public function getAvatarAttribute(): string
8
    {
9
        return 'https://www.gravatar.com/avatar/'.md5($this->email).'?d=mm&s=256';
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...
10
    }
11
12
    public function getLastActivityDateAttribute(): string
13
    {
14
        if ($this->last_activity === null || $this->last_activity->year == -1) {
0 ignored issues
show
Bug introduced by
The property last_activity 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...
15
            return fragment('back.frontUsers.neverLoggedIn');
16
        }
17
18
        $lastActivityDate = diff_date_for_humans($this->last_activity);
19
20
        if (str_contains($lastActivityDate, 'second')) {
21
            $lastActivityDate = fragment('back.frontUsers.justNow');
22
        }
23
24
        return $lastActivityDate;
25
    }
26
}
27