LastFmException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 40
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getErrorMessage() 0 6 2
1
<?php
2
namespace Sourceout\LastFm\Providers\LastFm\Exception;
3
4
use Sourceout\LastFm\Exception\ClientException;
5
6
class LastFmException extends ClientException
7
{
8
    const ERRORS = [
9
            2 => "Invalid service - This service does not exist",
10
            3 => "Invalid Method - No method with that name in this package",
11
            4 => "Authentication Failed - You do not have permissions to access the service",
12
            5 => "Invalid format - This service doesn't exist in that format",
13
            6 => "Invalid parameters - Your request is missing a required parameter",
14
            7 => "Invalid resource specified",
15
            8 => "Operation failed - Something else went wrong",
16
            9 => "Invalid session key - Please re-authenticate",
17
            10 => "Invalid API key - You must be granted a valid key by last.fm",
18
            11 => "Service Offline - This service is temporarily offline. Try again later.",
19
            13 => "Invalid method signature supplied",
20
            16 => "There was a temporary error processing your request. Please try again",
21
            26 => "Suspended API key - Access for your account has been suspended, please contact Last.fm",
22
            29 => "Rate limit exceeded - Your IP has made too many requests in a short period "
23
    ];
24
25 3
    public function __construct($message, $code, $previous = null)
26
    {
27
        $message = [
28 3
            "message" => $this->getErrorMessage($code),
29 3
            "error" => $message
30
        ];
31 3
        parent::__construct(json_encode($message), $code, $previous);
32 3
    }
33
34
    /**
35
     * Return back platform specific message corresponding to a code
36
     *
37
     * @param int $code
38
     * @return string
39
     */
40 3
    private function getErrorMessage($code) : string
41
    {
42 3
        if (isset(LastFmException::ERRORS[$code])) {
43 1
            return LastFmException::ERRORS[$code];
44
        }
45 2
        return 'An unknown error occurred. Please try again later';
46
    }
47
}