Completed
Push — master ( 5049fe...5fd7f0 )
by Sherif
02:43
created

ErrorHandler   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

13 Methods

Rating   Name   Duplication   Size   Complexity  
A unAuthorized() 0 5 1
A tokenExpired() 0 5 1
A noPermissions() 0 5 1
A loginFailed() 0 5 1
A redisNotRunning() 0 5 1
A dbQueryError() 0 5 1
A cannotCreateSetting() 0 5 1
A cannotUpdateSettingKey() 0 5 1
A userIsBlocked() 0 5 1
A invalidResetToken() 0 5 1
A invalidResetPassword() 0 5 1
A notFound() 0 5 1
A generalError() 0 5 1
1
<?php namespace App\Modules\V1\Core\Utl;
2
3
class ErrorHandler
4
{
5
    public function unAuthorized()
6
    {
7
        $error = ['status' => 401, 'message' => 'Please login before any action'];
8
        abort($error['status'], $error['message']);
9
    }
10
11
    public function tokenExpired()
12
    {
13
        $error = ['status' => 403, 'message' => 'Login token expired'];
14
        abort($error['status'], $error['message']);
15
    }
16
17
     public function noPermissions()
18
    {
19
        $error = ['status' => 403, 'message' => 'No permissions'];
20
        abort($error['status'], $error['message']);
21
    }
22
23
    public function loginFailed()
24
    {
25
        $error = ['status' => 400, 'message' => 'Wrong mail or password'];
26
        abort($error['status'], $error['message']);
27
    }
28
29
    public function redisNotRunning()
30
    {
31
        $error = ['status' => 400, 'message' => 'Your redis notification server isn\'t running'];
32
        abort($error['status'], $error['message']);
33
    }
34
35
    public function dbQueryError()
36
    {
37
        $error = ['status' => 400, 'message' => 'Please check the given inputes'];
38
        abort($error['status'], $error['message']);
39
    }
40
41
    public function cannotCreateSetting()
42
    {
43
        $error = ['status' => 400, 'message' => 'Can\'t create setting'];
44
        abort($error['status'], $error['message']);
45
    }
46
47
    public function cannotUpdateSettingKey()
48
    {
49
        $error = ['status' => 400, 'message' => 'Can\'t update setting key'];
50
        abort($error['status'], $error['message']);
51
    }
52
53
    public function userIsBlocked()
54
    {
55
        $error = ['status' => 403, 'message' => 'You have been blocked'];
56
        abort($error['status'], $error['message']);
57
    }
58
59
    public function invalidResetToken()
60
    {
61
        $error = ['status' => 400, 'message' => 'Reset password token is invalid'];
62
        abort($error['status'], $error['message']);
63
    }
64
65
    public function invalidResetPassword()
66
    {
67
        $error = ['status' => 400, 'message' => 'Reset password is invalid'];
68
        abort($error['status'], $error['message']);
69
    }
70
71
    public function notFound($text)
72
    {
73
        $error = ['status' => 404, 'message' => 'The requested ' . $text . ' not found'];
74
        abort($error['status'], $error['message']);
75
    }
76
77
    public function generalError()
78
    {
79
        $error = ['status' => 404, 'message' => 'Something went wrong'];
80
        abort($error['status'], $error['message']);
81
    }
82
}