Completed
Pull Request — master (#274)
by
unknown
63:55 queued 33:13
created

UserPresenter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Thinktomorrow\Chief\Users;
4
5
class UserPresenter
6
{
7
    /**
8
     * @var User
9
     */
10
    private $user;
11
12 2
    public function __construct(User $user)
13
    {
14 2
        $this->user = $user;
15 2
    }
16
17 2
    public function enabledAsLabel(): string
18
    {
19
        // Avoid showing enabled state if there is an invitation pending
20 2
        if ($this->user->invitation->last()) {
21
            $state = $this->user->invitation->last()->state();
22
            if ($state == 'pending') {
23
                return '<span class="label label-primary">Uitgenodigd</span>';
24
            } elseif ($state == 'denied') {
25
                return '<span class="label label-error">Geblokkeerd</span>';
26
            }
27
        }
28
29 2
        return $this->user->isEnabled()
30
            ? ''
31 2
            : '<span class="label label-error">Geblokkeerd</span>';
32
    }
33
}
34