Completed
Push — master ( 30bf22...1e8707 )
by
unknown
02:45
created

RestApiEventSubscriberFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 7
dl 0
loc 35
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 27 5
1
<?php
2
3
namespace MediaMonks\RestApi\EventSubscriber;
4
5
use MediaMonks\RestApi\Model\ResponseModel;
6
use MediaMonks\RestApi\Model\ResponseModelFactory;
7
use MediaMonks\RestApi\Request\PathRequestMatcher;
8
use MediaMonks\RestApi\Request\RequestTransformer;
9
use MediaMonks\RestApi\Response\ResponseTransformer;
10
use MediaMonks\RestApi\Serializer\JsonSerializer;
11
12
class RestApiEventSubscriberFactory
13
{
14
    /**
15
     * @param string $path
16
     * @param array $options
17
     * @return RestApiEventSubscriber
18
     */
19 2
    public static function create($path = '/api', array $options = [])
20
    {
21 2
        if (empty($options['serializer'])) {
22 2
            $options['serializer'] = new JsonSerializer();
23 2
        }
24 2
        if (empty($options['response_model'])) {
25 2
            $options['responseModel'] = new ResponseModel();
26 2
        }
27 2
        $responseTransformerOptions = [];
28 2
        if (isset($options['debug'])) {
29 1
            $responseTransformerOptions['debug'] = $options['debug'];
30 1
        }
31 2
        if (isset($options['post_message_origin'])) {
32 1
            $responseTransformerOptions['post_message_origin'] = $options['post_message_origin'];
33 1
        }
34
35 2
        $requestMatcher = new PathRequestMatcher($path);
36 2
        $requestTransformer = new RequestTransformer($options['serializer']);
37 2
        $responseModelFactory = new ResponseModelFactory($options['responseModel']);
38 2
        $responseTransformer = new ResponseTransformer(
39 2
            $options['serializer'],
40 2
            $responseModelFactory,
41
            $responseTransformerOptions
42 2
        );
43
44 2
        return new RestApiEventSubscriber($requestMatcher, $requestTransformer, $responseTransformer);
45
    }
46
}
47