Passed
Push — master ( b16a12...abed16 )
by Ax
09:12
created

SleeperHttpException::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 12
rs 10
1
<?php
2
3
namespace SchoppAx\Sleeper\Api;
4
5
use Throwable;
6
7
class SleeperHttpException extends \Exception
8
{
9
10
  /**
11
   * List of HTTP status codes
12
   *
13
   * From https://docs.sleeper.app/#errors
14
   *
15
   * @var array
16
   */
17
  private $status = array(
18
      400 => 'Bad Request - Your request is invalid.',
19
      404 => 'Not Found - The specified kitten could not be found.',
20
      429 => "Too Many Requests - You're requesting too many kittens! Slow down!",
21
      500 => 'Internal Server Error - We had a problem with our server. Try again later.',
22
      503 => "Service Unavailable - We're temporarily offline for maintenance. Please try again later."
23
  );
24
25
  /**
26
   * @param int[optional]    $statusCode   If NULL will use 500 as default
27
   * @param string[optional] $statusMsg If NULL will use the default status phrase
28
   */
29
  public function __construct($statusCode = 500, $statusMsg = null)
30
  {
31
    if (null === $statusMsg && isset($this->status[$statusCode])) {
32
      $statusMsg = $this->status[$statusCode];
33
    }
34
    parent::__construct($statusMsg, $statusCode);
35
  }
36
37
}
38