Completed
Pull Request — 5.x (#1165)
by
unknown
02:02
created

FacebookGuzzleHttpClient::getHeadersAsString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright 2017 Facebook, Inc.
4
 *
5
 * You are hereby granted a non-exclusive, worldwide, royalty-free license to
6
 * use, copy, modify, and distribute this software in source code or binary
7
 * form for use in connection with the web services and APIs provided by
8
 * Facebook.
9
 *
10
 * As with any software that integrates with the Facebook platform, your use
11
 * of this software is subject to the Facebook Developer Principles and
12
 * Policies [http://developers.facebook.com/policy/]. This copyright notice
13
 * shall be included in all copies or substantial portions of the software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * DEALINGS IN THE SOFTWARE.
22
 *
23
 */
24
namespace Facebook\HttpClients;
25
26
use Facebook\Http\GraphRawResponse;
27
use Facebook\Exceptions\FacebookSDKException;
28
29
use GuzzleHttp\Client;
30
use GuzzleHttp\Psr7\Request;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\Psr7\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use GuzzleHttp\Message\ResponseInterface;
32
use GuzzleHttp\Ring\Exception\RingException;
33
use GuzzleHttp\Exception\RequestException;
34
35
class FacebookGuzzleHttpClient implements FacebookHttpClientInterface
36
{
37
    /**
38
     * @var \GuzzleHttp\Client The Guzzle client.
39
     */
40
    protected $guzzleClient;
41
42
    /**
43
     * @param \GuzzleHttp\Client|null The Guzzle client.
0 ignored issues
show
Bug introduced by
The type Facebook\HttpClients\The was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
44
     */
45
    public function __construct()
46
    {
47
        $this->guzzleClient = new Client();
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function send($url, $method, $body, array $headers, $timeOut)
54
    {
55
        $request = new Request($method, $url, $headers, $body);
56
57
        try {
58
            $response = $this->guzzleClient->send($request, ['timeout' => $timeOut, 'http_errors' => false]);
0 ignored issues
show
Unused Code introduced by
The call to GuzzleHttp\Client::send() has too many arguments starting with array('timeout' => $time...'http_errors' => false). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
            /** @scrutinizer ignore-call */ 
59
            $response = $this->guzzleClient->send($request, ['timeout' => $timeOut, 'http_errors' => false]);

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. Please note the @ignore annotation hint above.

Loading history...
59
        } catch (GuzzleHttp\Exception\RequestException $e) {
0 ignored issues
show
Bug introduced by
The type Facebook\HttpClients\Guz...eption\RequestException was not found. Did you mean GuzzleHttp\Exception\RequestException? If so, make sure to prefix the type with \.
Loading history...
60
            throw new FacebookSDKException($e->getMessage(), $e->getCode());
61
        }
62
63
        $httpStatusCode = $response->getStatusCode();
0 ignored issues
show
Bug introduced by
The method getStatusCode() does not exist on GuzzleHttp\Ring\Future\FutureInterface. It seems like you code against a sub-type of GuzzleHttp\Ring\Future\FutureInterface such as GuzzleHttp\Message\FutureResponse. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
        /** @scrutinizer ignore-call */ 
64
        $httpStatusCode = $response->getStatusCode();
Loading history...
64
        $responseHeaders = $response->getHeaders();
0 ignored issues
show
Bug introduced by
The method getHeaders() does not exist on GuzzleHttp\Ring\Future\FutureInterface. It seems like you code against a sub-type of GuzzleHttp\Ring\Future\FutureInterface such as GuzzleHttp\Message\FutureResponse. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
        /** @scrutinizer ignore-call */ 
65
        $responseHeaders = $response->getHeaders();
Loading history...
65
        foreach ($responseHeaders as $key => $values) {
66
            $responseHeaders[$key] = implode(', ', $values);
67
        }
68
69
        $responseBody = $response->getBody()->getContents();
0 ignored issues
show
Bug introduced by
The method getBody() does not exist on GuzzleHttp\Ring\Future\FutureInterface. It seems like you code against a sub-type of GuzzleHttp\Ring\Future\FutureInterface such as GuzzleHttp\Message\FutureResponse. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
        $responseBody = $response->/** @scrutinizer ignore-call */ getBody()->getContents();
Loading history...
70
71
        return new GraphRawResponse(
72
            $responseHeaders,
73
            $responseBody,
74
            $httpStatusCode
75
        );
76
    }
77
}
78