Code Duplication    Length = 60-64 lines in 2 locations

src/ApiProblem/ClientError/MethodNotAllowed.php 1 location

@@ 9-68 (lines=60) @@
6
7
use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem;
8
9
final class MethodNotAllowed extends AbstractApiProblem
10
{
11
    /**
12
     * @var string
13
     */
14
    private $method;
15
16
    /**
17
     * @var string[]
18
     */
19
    private $allowedMethods = [];
20
21
    /**
22
     * @param string      $method,
23
     * @param string[]    $allowedMethods
24
     * @param string|null $detail
25
     * @param string|null $instance
26
     */
27
    public function __construct(string $method, array $allowedMethods, string $detail = null, string $instance = null)
28
    {
29
        parent::__construct(
30
            'https://tools.ietf.org/html/rfc2616#section-10.4.6',
31
            405,
32
            'Method Not Allowed',
33
            $detail,
34
            $instance
35
        );
36
37
        $this->method = $method;
38
        $this->allowedMethods = $allowedMethods;
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    public function getHeaders(): array
45
    {
46
        if ([] === $this->allowedMethods) {
47
            return [];
48
        }
49
50
        return ['Allow' => implode(',', $this->allowedMethods)];
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getMethod(): string
57
    {
58
        return $this->method;
59
    }
60
61
    /**
62
     * @return string[]
63
     */
64
    public function getAllowedMethods(): array
65
    {
66
        return $this->allowedMethods;
67
    }
68
}
69

src/ApiProblem/ClientError/NotAcceptable.php 1 location

@@ 9-72 (lines=64) @@
6
7
use Chubbyphp\ApiHttp\ApiProblem\AbstractApiProblem;
8
9
final class NotAcceptable extends AbstractApiProblem
10
{
11
    /**
12
     * @var string
13
     */
14
    private $accept;
15
16
    /**
17
     * @var string[]
18
     */
19
    private $acceptables = [];
20
21
    /**
22
     * @param string      $accept
23
     * @param string[]    $acceptables
24
     * @param string|null $detail
25
     * @param string|null $instance
26
     */
27
    public function __construct(
28
        string $accept,
29
        array $acceptables,
30
        string $detail = null,
31
        string $instance = null
32
    ) {
33
        parent::__construct(
34
            'https://tools.ietf.org/html/rfc2616#section-10.4.7',
35
            406,
36
            'Not Acceptable',
37
            $detail,
38
            $instance
39
        );
40
41
        $this->accept = $accept;
42
        $this->acceptables = $acceptables;
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getHeaders(): array
49
    {
50
        if ([] === $this->acceptables) {
51
            return [];
52
        }
53
54
        return ['X-Acceptables' => implode(',', $this->acceptables)];
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function getAccept(): string
61
    {
62
        return $this->accept;
63
    }
64
65
    /**
66
     * @return string[]
67
     */
68
    public function getAcceptables(): array
69
    {
70
        return $this->acceptables;
71
    }
72
}
73