UserPresenter   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 0
loc 86
c 3
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A gravatar() 0 6 1
B statusLabel() 0 23 4
B status() 0 16 6
1
<?php namespace Anomaly\UsersModule\User;
2
3
use Anomaly\Streams\Platform\Entry\EntryPresenter;
4
use Anomaly\UsersModule\User\Contract\UserInterface;
5
6
/**
7
 * Class UserPresenter
8
 *
9
 * @link          http://pyrocms.com/
10
 * @author        PyroCMS, Inc. <[email protected]>
11
 * @author        Ryan Thompson <[email protected]>
12
 */
13
class UserPresenter extends EntryPresenter
14
{
15
16
    /**
17
     * The decorated object.
18
     * This is for IDE support.
19
     *
20
     * @var UserInterface
21
     */
22
    protected $object;
23
24
    /**
25
     * Return the users name.
26
     *
27
     * @return string
28
     */
29
    public function name()
30
    {
31
        return implode(' ', array_filter([$this->object->getFirstName(), $this->object->getLastName()]));
32
    }
33
34
    /**
35
     * Return the user gravatar.
36
     *
37
     * @param  array  $parameters
38
     * @return string
39
     */
40
    public function gravatar($parameters = [])
41
    {
42
        return 'https://www.gravatar.com/avatar/' . md5($this->object->getEmail()) . '?' . http_build_query(
43
            $parameters
44
        );
45
    }
46
47
    /**
48
     * Return the user's status as a label.
49
     *
50
     * @param  string      $size
51
     * @return null|string
52
     */
53
    public function statusLabel($size = 'sm')
54
    {
55
        $color  = 'default';
56
        $status = $this->status();
57
58
        switch ($status) {
59
            case 'active':
60
                $color = 'success';
61
                break;
62
63
            case 'inactive':
64
                $color = 'default';
65
                break;
66
67
            case 'disabled':
68
                $color = 'danger';
69
                break;
70
        }
71
72
        return '<span class="label label-' . $size . ' label-' . $color . '">' . trans(
73
            'anomaly.module.users::field.status.option.' . $status
74
        ) . '</span>';
75
    }
76
77
    /**
78
     * Return the status key.
79
     *
80
     * @return null|string
81
     */
82
    public function status()
83
    {
84
        if (!$this->object->isEnabled()) {
85
            return 'disabled';
86
        }
87
88
        if ($this->object->isEnabled() && !$this->object->isActivated()) {
89
            return 'inactive';
90
        }
91
92
        if ($this->object->isEnabled() && $this->object->isActivated()) {
93
            return 'active';
94
        }
95
96
        return null;
97
    }
98
}
99