1 | <?php |
||
23 | final class PluginClient implements HttpClient, HttpAsyncClient |
||
24 | { |
||
25 | /** |
||
26 | * An HTTP async client. |
||
27 | * |
||
28 | * @var HttpAsyncClient|HttpClient |
||
29 | */ |
||
30 | private $client; |
||
31 | |||
32 | /** |
||
33 | * The plugin chain. |
||
34 | * |
||
35 | * @var Plugin[] |
||
36 | */ |
||
37 | private $plugins; |
||
38 | |||
39 | /** |
||
40 | * A list of options. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | private $options; |
||
45 | |||
46 | /** |
||
47 | * @param ClientInterface|HttpAsyncClient $client |
||
48 | * @param Plugin[] $plugins |
||
49 | * @param array $options { |
||
50 | * |
||
51 | * @var int $max_restarts |
||
52 | * } |
||
53 | */ |
||
54 | 10 | public function __construct($client, array $plugins = [], array $options = []) |
|
55 | { |
||
56 | 10 | if ($client instanceof HttpAsyncClient) { |
|
57 | 3 | $this->client = $client; |
|
58 | 7 | } elseif ($client instanceof ClientInterface) { |
|
59 | 7 | $this->client = new EmulatedHttpAsyncClient($client); |
|
60 | } else { |
||
61 | throw new \TypeError( |
||
62 | sprintf('%s::__construct(): Argument #1 ($client) must be of type %s|%s, %s given', self::class, ClientInterface::class, HttpAsyncClient::class, get_debug_type($client)) |
||
|
|||
63 | ); |
||
64 | } |
||
65 | |||
66 | 10 | $this->plugins = $plugins; |
|
67 | 10 | $this->options = $this->configure($options); |
|
68 | 10 | } |
|
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | 4 | public function sendRequest(RequestInterface $request): ResponseInterface |
|
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | 2 | public function sendAsyncRequest(RequestInterface $request) |
|
104 | |||
105 | /** |
||
106 | * Configure the plugin client. |
||
107 | */ |
||
108 | 10 | private function configure(array $options = []): array |
|
119 | |||
120 | /** |
||
121 | * Create the plugin chain. |
||
122 | * |
||
123 | * @param Plugin[] $pluginList A list of plugins |
||
124 | * @param callable $clientCallable Callable making the HTTP call |
||
125 | */ |
||
126 | 5 | private function createPluginChain(array $pluginList, callable $clientCallable): callable |
|
151 | } |
||
152 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.