Completed
Push — master ( 783bbe...a130e0 )
by
unknown
05:27
created

RestApiEventSubscriberFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 7
dl 0
loc 39
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C create() 0 32 7
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 array $options
16
     * @return RestApiEventSubscriber
17
     */
18 2
    public static function create(array $options = [])
19
    {
20 2
        if (empty($options['path'])) {
21 2
            $options['path'] = '/api';
22 2
        }
23 2
        if (empty($options['serializer'])) {
24 2
            $options['serializer'] = new JsonSerializer();
25 2
        }
26 2
        if (empty($options['response_model'])) {
27 2
            $options['response_model'] = new ResponseModel();
28 2
        }
29 2
        if (empty($options['request_matcher'])) {
30 2
            $options['request_matcher'] =  new PathRequestMatcher($options['path']);
31 2
        }
32 2
        $responseTransformerOptions = [];
33 2
        if (isset($options['debug'])) {
34 1
            $responseTransformerOptions['debug'] = $options['debug'];
35 1
        }
36 2
        if (isset($options['post_message_origin'])) {
37 1
            $responseTransformerOptions['post_message_origin'] = $options['post_message_origin'];
38 1
        }
39
40 2
        $requestTransformer = new RequestTransformer($options['serializer']);
41 2
        $responseModelFactory = new ResponseModelFactory($options['response_model']);
42 2
        $responseTransformer = new ResponseTransformer(
43 2
            $options['serializer'],
44 2
            $responseModelFactory,
45
            $responseTransformerOptions
46 2
        );
47
48 2
        return new RestApiEventSubscriber($options['request_matcher'], $requestTransformer, $responseTransformer);
49
    }
50
}
51