Passed
Push — master ( a7da05...21ccf8 )
by Darko
10:04
created

SignupError   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 18
dl 0
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isSuccess() 0 3 1
A message() 0 10 1
A isError() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Enums;
6
7
enum SignupError: int
8
{
9
    case BAD_USERNAME = -1;
10
    case BAD_PASSWORD = -2;
11
    case BAD_EMAIL = -3;
12
    case USERNAME_IN_USE = -4;
13
    case EMAIL_IN_USE = -5;
14
    case BAD_INVITE_CODE = -6;
15
    case SUCCESS = 1;
16
17
    public function message(): string
18
    {
19
        return match ($this) {
20
            self::BAD_USERNAME => 'Invalid username provided.',
21
            self::BAD_PASSWORD => 'Invalid password provided.',
22
            self::BAD_EMAIL => 'Invalid email address provided.',
23
            self::USERNAME_IN_USE => 'Username is already in use.',
24
            self::EMAIL_IN_USE => 'Email address is already in use.',
25
            self::BAD_INVITE_CODE => 'Invalid or expired invite code.',
26
            self::SUCCESS => 'Registration successful.',
27
        };
28
    }
29
30
    public function isError(): bool
31
    {
32
        return $this->value < 0;
33
    }
34
35
    public function isSuccess(): bool
36
    {
37
        return $this === self::SUCCESS;
38
    }
39
}
40
41