Failed Conditions
Pull Request — master (#27)
by Chad
01:45
created

ResponseBridge   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 3
c 5
b 1
f 0
lcom 0
cbo 2
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromOauth2() 0 15 3
1
<?php
2
namespace Chadicus\Slim\OAuth2\Http;
3
4
use OAuth2;
5
use Zend\Diactoros\Response;
6
use Zend\Diactoros\Stream;
7
8
/**
9
 * Static utility class for bridging OAuth2 responses to PSR-7 responses.
10
 */
11
class ResponseBridge
12
{
13
    /**
14
     * Copies values from the given Oauth2\Response to a PSR-7 Http Response.
15
     *
16
     * @param OAuth2\ResponseInterface $oauth2Response The OAuth2 server response.
17
     *
18
     * @return \Psr\Http\Message\ResponseInterface
19
     */
20
    final public static function fromOauth2(OAuth2\ResponseInterface $oauth2Response)
21
    {
22
        $headers = [];
23
        foreach ($oauth2Response->getHttpHeaders() as $key => $value) {
24
            $headers[$key] = explode(', ', $value);
25
        }
26
27
        $stream = fopen('php://temp', 'r+');
28
        if (!empty($oauth2Response->getParameters())) {
0 ignored issues
show
Bug introduced by
The method getParameters() does not exist on OAuth2\ResponseInterface. Did you maybe mean getParameter()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
29
            fwrite($stream, $oauth2Response->getResponseBody());
30
            rewind($stream);
31
        }
32
33
        return new Response(new Stream($stream), $oauth2Response->getStatusCode(), $headers);
34
    }
35
}
36