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 Http\HttplugBundle; |
||
4 | |||
5 | use Http\Client\HttpClient; |
||
6 | use Http\Discovery\Exception\StrategyUnavailableException; |
||
7 | use Http\Discovery\HttpClientDiscovery; |
||
8 | use Http\Discovery\Strategy\DiscoveryStrategy; |
||
9 | |||
10 | /** |
||
11 | * A strategy that provide clients configured with HTTPlug bundle. |
||
12 | * |
||
13 | * @author Tobias Nyholm <[email protected]> |
||
14 | */ |
||
15 | class ConfiguredClientsStrategy implements DiscoveryStrategy |
||
16 | { |
||
17 | /** |
||
18 | * @var HttpClient |
||
19 | */ |
||
20 | private static $client; |
||
21 | |||
22 | /** |
||
23 | * @param HttpClient $httpClient |
||
24 | */ |
||
25 | public function __construct(HttpClient $httpClient) |
||
26 | { |
||
27 | static::$client = $httpClient; |
||
0 ignored issues
–
show
|
|||
28 | |||
29 | HttpClientDiscovery::prependStrategy(self::class); |
||
0 ignored issues
–
show
The method
prependStrategy() does not seem to exist on object<Http\Discovery\HttpClientDiscovery> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
30 | } |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | public static function getCandidates($type) |
||
36 | { |
||
37 | if (static::$client !== null && $type == 'Http\Client\HttpClient') { |
||
0 ignored issues
–
show
Since
$client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $client to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
38 | return [['class' => function() { return static::$client; }]]; |
||
0 ignored issues
–
show
Since
$client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $client to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
39 | } |
||
40 | |||
41 | return []; |
||
42 | } |
||
43 | } |
||
44 |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: