Completed
Push — master ( e64a87...c98c99 )
by
unknown
07:13
created

RestApiEventSubscriberFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 7
dl 0
loc 35
ccs 18
cts 22
cp 0.8182
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 1
    public static function create($path = '/api', array $options = [])
20
    {
21 1
        if (empty($options['serializer'])) {
22 1
            $options['serializer'] = new JsonSerializer();
23 1
        }
24 1
        if (empty($options['response_model'])) {
25 1
            $options['responseModel'] = new ResponseModel();
26 1
        }
27 1
        $responseTransformerOptions = [];
28 1
        if (isset($options['debug'])) {
29
            $responseTransformerOptions['debug'] = $options['debug'];
30
        }
31 1
        if (isset($options['post_message_origin'])) {
32
            $responseTransformerOptions['post_message_origin'] = $options['post_message_origin'];
33
        }
34
35 1
        $requestMatcher = new PathRequestMatcher($path);
36 1
        $requestTransformer = new RequestTransformer($options['serializer']);
37 1
        $responseModelFactory = new ResponseModelFactory($options['responseModel']);
38 1
        $responseTransformer = new ResponseTransformer(
39 1
            $options['serializer'],
40 1
            $responseModelFactory,
41
            $responseTransformerOptions
42 1
        );
43
44 1
        return new RestApiEventSubscriber($requestMatcher, $requestTransformer, $responseTransformer);
45
    }
46
}
47