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
|
|||
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
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(), |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Psr\Http\Message\MessageInterface as the method getStatusCode() does only exist in the following implementations of said interface: GuzzleHttp\Psr7\Response .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
37 | $input->getReasonPhrase() |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Psr\Http\Message\MessageInterface as the method getReasonPhrase() does only exist in the following implementations of said interface: GuzzleHttp\Psr7\Response .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
38 | ); |
||
39 | |||
40 | $this->importHeaders($input, $adapted); |
||
41 | |||
42 | return $adapted; |
||
43 | } |
||
44 | } |
||
45 |
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:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: