Failed Conditions
Pull Request — master (#18)
by Chad
01:56
created

ResponseBridge::fromOauth2()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 17
rs 9.4285
cc 3
eloc 11
nc 4
nop 1
1
<?php
2
namespace Chadicus\Slim\OAuth2\Http;
3
4
use Slim\Http\Headers;
5
use Slim\Http\Response;
6
use Slim\Http\Stream;
7
use OAuth2;
8
9
/**
10
 * Static utility class for bridging OAuth2 responses to PSR-7 responses.
11
 */
12
class ResponseBridge
13
{
14
    /**
15
     * Copies values from the given Oauth2\Response to a Slim Response.
16
     *
17
     * @param OAuth2\ResponseInterface $oauth2Response The OAuth2 server response.
18
     *
19
     * @return Response
20
     */
21
    final public static function fromOauth2(OAuth2\ResponseInterface $oauth2Response)
22
    {
23
        $headers = new Headers();
24
        foreach ($oauth2Response->getHttpHeaders() as $key => $value) {
25
            $headers->set($key, explode(', ', $value));
0 ignored issues
show
Documentation introduced by
explode(', ', $value) is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
26
        }
27
28
        $body = new Stream(fopen('php://temp', 'r'));
29
        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...
30
            $stream = fopen('php://memory','r+');
31
            fwrite($stream, $oauth2Response->getResponseBody());
32
            rewind($stream);
33
            $body = new Stream($stream);
34
        }
35
36
        return new Response($oauth2Response->getStatusCode(), $headers, $body);
37
    }
38
}
39