Completed
Push — master ( f8712b...8ebca4 )
by Jared
04:10
created

SymfonyHttpBridge   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 8
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convertSymfonyRequest() 0 11 2
A convertInfuseResponse() 0 4 1
1
<?php
2
3
namespace Infuse;
4
5
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
6
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
7
8
/**
9
 * Converts Symfony request/response objects to
10
 * Infuse request/response objects, and vice-versa.
11
 */
12
class SymfonyHttpBridge
13
{
14
    /**
15
     * Converts a Symfony request object into an Infuse request object.
16
     *
17
     * @param SymfonyRequest $request
18
     *
19
     * @return Request
20
     */
21
    public function convertSymfonyRequest(SymfonyRequest $request)
22
    {
23
        $session = $request->getSession();
24
        if ($session) {
25
            $session = $session->all();
26
        } else {
27
            $session = [];
28
        }
29
30
        return new Request($request->query->all(), $request->request->all(), $request->cookies->all(), $request->files->all(), $request->server->all(), $session);
31
    }
32
33
    /**
34
     * Converts an Infuse response object into a Symfony response object.
35
     *
36
     * @param Response $res
37
     *
38
     * @return SymfonyResponse
39
     */
40
    public function convertInfuseResponse(Response $res)
41
    {
42
        return new SymfonyResponse($res->getBody(), $res->getCode(), $res->headers());
0 ignored issues
show
Bug introduced by
It seems like $res->headers() targeting Infuse\Response::headers() can also be of type null or string; however, Symfony\Component\HttpFo...Response::__construct() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
43
    }
44
}
45