Completed
Branch master (a6481d)
by Fèvre
02:12
created

UserPresenter   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 88
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getFirstNameAttribute() 0 4 1
A getLastNameAttribute() 0 4 1
A getFullNameAttribute() 0 4 1
A getFacebookAttribute() 0 4 1
A getTwitterAttribute() 0 4 1
A getBiographyAttribute() 0 4 1
A getSignatureAttribute() 0 4 1
A parse() 0 8 2
1
<?php
2
namespace Xetaravel\Models\Presenters;
3
4
trait UserPresenter
5
{
6
    /**
7
     * Get the account first name.
8
     *
9
     * @return string
10
     */
11
    public function getFirstNameAttribute(): string
12
    {
13
        return $this->parse($this->account->first_name);
0 ignored issues
show
Bug introduced by
The property account 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...
14
    }
15
16
    /**
17
     * Get the account last name.
18
     *
19
     * @return string
20
     */
21
    public function getLastNameAttribute(): string
22
    {
23
        return $this->parse($this->account->last_name);
24
    }
25
26
    /**
27
     * Get the account full name.
28
     *
29
     * @return string
30
     */
31
    public function getFullNameAttribute(): string
32
    {
33
        return $this->parse($this->account->first_name) . ' ' . $this->parse($this->account->last_name);
34
    }
35
36
    /**
37
     * Get the account facebook.
38
     *
39
     * @return string
40
     */
41
    public function getFacebookAttribute(): string
42
    {
43
        return $this->parse($this->account->facebook);
44
    }
45
46
    /**
47
     * Get the account twitter.
48
     *
49
     * @return string
50
     */
51
    public function getTwitterAttribute(): string
52
    {
53
        return $this->parse($this->account->twitter);
54
    }
55
56
    /**
57
     * Get the account biography.
58
     *
59
     * @return string
60
     */
61
    public function getBiographyAttribute(): string
62
    {
63
        return $this->parse($this->account->biography);
64
    }
65
66
    /**
67
     * Get the account signature.
68
     *
69
     * @return string
70
     */
71
    public function getSignatureAttribute(): string
72
    {
73
        return $this->parse($this->account->signature);
74
    }
75
76
    /**
77
     * Parse an attribute and return its value or empty if null.
78
     *
79
     * @param string|null $attribute The attribute to parse.
80
     *
81
     * @return string
82
     */
83
    protected function parse($attribute): string
84
    {
85
        if ($attribute === null) {
86
            return '';
87
        }
88
        
89
        return $attribute;
90
    }
91
}
92