Completed
Push — master ( 2628ea...09221c )
by Dawid
10s
created

GenericHttpException::invalidUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Igni\Http\Exception;
4
5
use Igni\Exception\RuntimeException;
6
use Igni\Http\Response;
7
8
class GenericHttpException extends RuntimeException implements HttpException
9
{
10
    public function getHttpStatusCode(): int
11
    {
12
        return $this->getCode();
13
    }
14
15
    public function getHttpBody(): string
16
    {
17
        return $this->getMessage();
18
    }
19
20
    public static function invalidUri($uri, $method): self
21
    {
22
        return new self("No resource found for $method $uri", Response::HTTP_NOT_FOUND);
23
    }
24
25
    public static function methodNotAllowed(string $uri, string $method, array $allowedMethods): self
26
    {
27
        $allowedMethods = implode(', ', $allowedMethods);
28
        $exception = new self(
29
            "Method `$method` not allowed. This uri `$uri` allows only $allowedMethods http methods.",
30
            Response::HTTP_METHOD_NOT_ALLOWED
31
        );
32
        return $exception;
33
    }
34
}
35