Completed
Push — develop ( 0a4bcc...0131cc )
by Kirill
25:10
created

Status::isNothing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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 App\Gitter\Middlewares\KarmaCounter;
12
13
use App\User;
14
15
/**
16
 * Class Status
17
 * @package App\Gitter\Middlewares\KarmaCounter
18
 */
19
class Status
20
{
21
    const STATUS_NOTHING    = 2;
22
    const STATUS_INCREMENT  = 4;
23
    const STATUS_TIMEOUT    = 8;
24
    const STATUS_SELF       = 16;
25
    const STATUS_NO_USER    = 32;
26
27
    /**
28
     * @var int
29
     */
30
    protected $status = self::STATUS_NOTHING;
31
32
    /**
33
     * @var User
34
     */
35
    protected $user;
36
37
    /**
38
     * Status constructor.
39
     * @param User $mention
40
     * @param int $status
41
     */
42
    public function __construct(User $mention, $status = self::STATUS_NOTHING)
43
    {
44
        $this->user = $mention;
45
        $this->status = $status;
46
    }
47
48
    /**
49
     * @return bool
50
     */
51
    public function isNothing()
52
    {
53
        return $this->status === static::STATUS_NOTHING;
54
    }
55
56
    /**
57
     * @return bool
58
     */
59
    public function isIncrement()
60
    {
61
        return $this->status === static::STATUS_INCREMENT;
62
    }
63
64
    /**
65
     * @return bool
66
     */
67
    public function isTimeout()
68
    {
69
        return $this->status === static::STATUS_TIMEOUT;
70
    }
71
72
    /**
73
     * @return bool
74
     */
75
    public function isSelf()
76
    {
77
        return $this->status === static::STATUS_SELF;
78
    }
79
80
    /**
81
     * @return bool
82
     */
83
    public function isNoUser()
84
    {
85
        return $this->status === static::STATUS_NO_USER;
86
    }
87
88
89
    /**
90
     * @return int
91
     */
92
    public function getStatus()
93
    {
94
        return $this->status;
95
    }
96
97
    /**
98
     * @return User
99
     */
100
    public function getUser()
101
    {
102
        return $this->user;
103
    }
104
105
    /**
106
     * @param $karma
107
     * @return string|null
108
     */
109
    public function getTranslation($karma)
110
    {
111
        $args = ['user' => $this->user->login, 'karma' => $karma];
112
113
        switch ($this->status) {
114
            case static::STATUS_INCREMENT:
115
                return trans('karma.increment', $args);
116
117
            case static::STATUS_TIMEOUT:
118
                return trans('karma.timeout', $args);
119
120
            case static::STATUS_SELF:
121
                return trans('karma.self', $args);
122
123
            case static::STATUS_NO_USER:
124
                return trans('karma.nouser', $args);
125
        }
126
127
        return null;
128
    }
129
}
130