UserPresenter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 10
wmc 5
lcom 2
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAvatarAttribute() 0 4 1
A getLastActivityDateAttribute() 0 14 4
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