Completed
Pull Request — master (#554)
by Alejandro
14:05
created

RestUtils::getRestErrorCodeFromException()   B

Complexity

Conditions 9
Paths 9

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 9.1582

Importance

Changes 0
Metric Value
cc 9
eloc 17
nc 9
nop 1
dl 0
loc 19
ccs 14
cts 16
cp 0.875
crap 9.1582
rs 8.0555
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Rest\Util;
6
7
use Shlinkio\Shlink\Common\Exception as Common;
8
use Shlinkio\Shlink\Core\Exception as Core;
9
use Shlinkio\Shlink\Rest\Exception as Rest;
10
use Throwable;
11
12
class RestUtils
13
{
14
    /** @deprecated */
15
    public const INVALID_SHORTCODE_ERROR = Core\ShortUrlNotFoundException::TYPE;
16
    /** @deprecated */
17
    public const INVALID_SHORTCODE_DELETION_ERROR = Core\DeleteShortUrlException::TYPE;
18
    /** @deprecated */
19
    public const INVALID_URL_ERROR = Core\InvalidUrlException::TYPE;
20
    /** @deprecated */
21
    public const INVALID_ARGUMENT_ERROR = Core\ValidationException::TYPE;
22
    /** @deprecated */
23
    public const INVALID_SLUG_ERROR = Core\NonUniqueSlugException::TYPE;
24
    /** @deprecated */
25
    public const INVALID_CREDENTIALS_ERROR = 'INVALID_CREDENTIALS';
26
    public const INVALID_AUTH_TOKEN_ERROR = 'INVALID_AUTH_TOKEN';
27
    public const INVALID_AUTHORIZATION_ERROR = 'INVALID_AUTHORIZATION';
28
    public const INVALID_API_KEY_ERROR = 'INVALID_API_KEY';
29
    /** @deprecated */
30
    public const NOT_FOUND_ERROR = Core\TagNotFoundException::TYPE;
31
    /** @deprecated */
32
    public const UNKNOWN_ERROR = 'UNKNOWN_ERROR';
33
34
    /** @deprecated */
35 1
    public static function getRestErrorCodeFromException(Throwable $e): string
36
    {
37
        switch (true) {
38 1
            case $e instanceof Core\ShortUrlNotFoundException:
39 1
                return self::INVALID_SHORTCODE_ERROR;
0 ignored issues
show
introduced by
The constant Shlinkio\Shlink\Rest\Uti...INVALID_SHORTCODE_ERROR has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

39
                return /** @scrutinizer ignore-deprecated */ self::INVALID_SHORTCODE_ERROR;
Loading history...
40 1
            case $e instanceof Core\InvalidUrlException:
41 1
                return self::INVALID_URL_ERROR;
0 ignored issues
show
introduced by
The constant Shlinkio\Shlink\Rest\Uti...tils::INVALID_URL_ERROR has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

41
                return /** @scrutinizer ignore-deprecated */ self::INVALID_URL_ERROR;
Loading history...
42 1
            case $e instanceof Core\NonUniqueSlugException:
43
                return self::INVALID_SLUG_ERROR;
0 ignored issues
show
introduced by
The constant Shlinkio\Shlink\Rest\Uti...ils::INVALID_SLUG_ERROR has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

43
                return /** @scrutinizer ignore-deprecated */ self::INVALID_SLUG_ERROR;
Loading history...
44 1
            case $e instanceof Common\InvalidArgumentException:
45 1
            case $e instanceof Core\InvalidArgumentException:
46 1
            case $e instanceof Core\ValidationException:
47 1
                return self::INVALID_ARGUMENT_ERROR;
0 ignored issues
show
introduced by
The constant Shlinkio\Shlink\Rest\Uti...:INVALID_ARGUMENT_ERROR has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

47
                return /** @scrutinizer ignore-deprecated */ self::INVALID_ARGUMENT_ERROR;
Loading history...
48 1
            case $e instanceof Rest\AuthenticationException:
49 1
                return self::INVALID_CREDENTIALS_ERROR;
0 ignored issues
show
introduced by
The constant Shlinkio\Shlink\Rest\Uti...VALID_CREDENTIALS_ERROR has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

49
                return /** @scrutinizer ignore-deprecated */ self::INVALID_CREDENTIALS_ERROR;
Loading history...
50 1
            case $e instanceof Core\DeleteShortUrlException:
51
                return self::INVALID_SHORTCODE_DELETION_ERROR;
0 ignored issues
show
introduced by
The constant Shlinkio\Shlink\Rest\Uti...HORTCODE_DELETION_ERROR has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

51
                return /** @scrutinizer ignore-deprecated */ self::INVALID_SHORTCODE_DELETION_ERROR;
Loading history...
52
            default:
53 1
                return self::UNKNOWN_ERROR;
0 ignored issues
show
introduced by
The constant Shlinkio\Shlink\Rest\Util\RestUtils::UNKNOWN_ERROR has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

53
                return /** @scrutinizer ignore-deprecated */ self::UNKNOWN_ERROR;
Loading history...
54
        }
55
    }
56
}
57