Completed
Push — master ( 704539...2a5253 )
by Robbie
02:16
created

src/HttpResponseAdapter.php (2 issues)

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
3
namespace Robbie\Psr7;
4
5
use GuzzleHttp\Psr7\Response;
6
use Psr\Http\Message\ResponseInterface;
7
use Robbie\Psr7\AbstractHttpAdapter;
8
use SilverStripe\Control\HTTPResponse;
9
10
/**
11
 * @package psr7-adapters
12
 */
13
class HttpResponseAdapter extends AbstractHttpAdapter
14
{
15
    /**
16
     * {@inheritDoc}
17
     */
18
    public function toPsr7($input)
19
    {
20
        return new Response(
21
            $input->getStatusCode(),
0 ignored issues
show
The method getStatusCode does only exist in SilverStripe\Control\HTTPResponse, but not in SilverStripe\Control\HTTPRequest.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
22
            $input->getHeaders(),
23
            $input->getBody(),
24
            $this->getProtocolVersion(),
25
            $input->getStatusDescription()
0 ignored issues
show
The method getStatusDescription does only exist in SilverStripe\Control\HTTPResponse, but not in SilverStripe\Control\HTTPRequest.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
26
        );
27
    }
28
29
    /**
30
     * {@inheritDoc}
31
     */
32
    public function fromPsr7($input)
33
    {
34
        $adapted = new HTTPResponse(
35
            (string) $input->getBody(),
36
            $input->getStatusCode(),
37
            $input->getReasonPhrase()
38
        );
39
40
        $this->importHeaders($input, $adapted);
41
42
        return $adapted;
43
    }
44
}
45