Completed
Push — master ( 354bbd...8413c0 )
by John
03:53
created

DefaultResponseFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getResponse() 0 8 2
A getSupportedTypes() 0 5 1
1
<?php
2
namespace LunixREST\Response;
3
4
use LunixREST\Response\Exceptions\UnknownResponseTypeException;
5
6
class DefaultResponseFactory implements ResponseFactory {
7
    /**
8
     * @param ResponseData $data
9
     * @param string $type
10
     * @return Response
11
     * @throws UnknownResponseTypeException
12
     */
13
    public function getResponse(ResponseData $data, string $type): Response {
14
        switch(strtolower($type)) {
15
            case "json":
16
                return new JSONResponse($data);
17
            default:
18
                throw new UnknownResponseTypeException("Unknown response type: $type");
19
        }
20
    }
21
22
    /**
23
     * @return string[]
24
     * @throws UnknownResponseTypeException
25
     */
26
    public function getSupportedTypes(): array {
27
        return [
28
            "json"
29
        ];
30
    }
31
}
32