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

src/ResponseBridge.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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