Status   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 111
rs 10
wmc 13
lcom 1
cbo 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isNothing() 0 4 1
A isIncrement() 0 4 1
A isTimeout() 0 4 1
A isSelf() 0 4 1
A isNoUser() 0 4 1
A getStatus() 0 4 1
A getUser() 0 4 1
B getTranslation() 0 20 5
1
<?php
2
/**
3
 * This file is part of GitterBot package.
4
 *
5
 * @author Serafim <[email protected]>
6
 * @date 09.10.2015 19:49
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Interfaces\Gitter\Karma;
12
13
use Domains\User;
14
15
class Status
16
{
17
    const STATUS_NOTHING    = 2;
18
    const STATUS_INCREMENT  = 4;
19
    const STATUS_TIMEOUT    = 8;
20
    const STATUS_SELF       = 16;
21
    const STATUS_NO_USER    = 32;
22
23
    /**
24
     * @var int
25
     */
26
    protected $status = self::STATUS_NOTHING;
27
28
    /**
29
     * @var User
30
     */
31
    protected $user;
32
33
    /**
34
     * Status constructor.
35
     * @param User $mention
36
     * @param int $status
37
     */
38
    public function __construct(User $mention, $status = self::STATUS_NOTHING)
39
    {
40
        $this->user = $mention;
41
        $this->status = $status;
42
    }
43
44
    /**
45
     * @return bool
46
     */
47
    public function isNothing()
48
    {
49
        return $this->status === static::STATUS_NOTHING;
50
    }
51
52
    /**
53
     * @return bool
54
     */
55
    public function isIncrement()
56
    {
57
        return $this->status === static::STATUS_INCREMENT;
58
    }
59
60
    /**
61
     * @return bool
62
     */
63
    public function isTimeout()
64
    {
65
        return $this->status === static::STATUS_TIMEOUT;
66
    }
67
68
    /**
69
     * @return bool
70
     */
71
    public function isSelf()
72
    {
73
        return $this->status === static::STATUS_SELF;
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    public function isNoUser()
80
    {
81
        return $this->status === static::STATUS_NO_USER;
82
    }
83
84
85
    /**
86
     * @return int
87
     */
88
    public function getStatus()
89
    {
90
        return $this->status;
91
    }
92
93
    /**
94
     * @return User
95
     */
96
    public function getUser()
97
    {
98
        return $this->user;
99
    }
100
101
    /**
102
     * @param $karma
103
     * @return string|null
104
     */
105
    public function getTranslation($karma)
106
    {
107
        $args = ['user' => $this->user->login, 'karma' => $karma];
108
109
        switch ($this->status) {
110
            case static::STATUS_INCREMENT:
111
                return trans('karma.increment', $args);
112
113
            case static::STATUS_TIMEOUT:
114
                return trans('karma.timeout', $args);
115
116
            case static::STATUS_SELF:
117
                return trans('karma.self', $args);
118
119
            case static::STATUS_NO_USER:
120
                return trans('karma.nouser', $args);
121
        }
122
123
        return null;
124
    }
125
}
126