GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Request::exec()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Request class that communicates with Telegram's web servers. Prepares an HTML request and instantiates
5
 * the Response object.
6
 *
7
 * @package Teebot (Telegram bot framework)
8
 *
9
 * @author  Stanislav Drozdov <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Teebot\Api;
15
16
use Teebot\Api\{
17
    Entity\EntityInterface,
18
    Method\AbstractMethod,
19
    Method\MethodInterface
20
};
21
22
class Request
23
{
24
    /**
25
     * @var HttpClient $client
26
     */
27
    protected $httpClient;
28
29
    /**
30
     * Request constructor.
31
     *
32
     * @param HttpClient $httpClient
33
     */
34
    public function __construct(HttpClient $httpClient)
35
    {
36
        $this->httpClient = $httpClient;
37
    }
38
39
    /**
40
     * Executes the Request to Telegram's servers and returns Response object.
41
     *
42
     * @param MethodInterface      $method Teebot method's instance to get arguments from
43
     * @param null|EntityInterface $parent Parent entity that initiated the Request
44
     *
45
     * @return Response
46
     */
47
    public function exec(MethodInterface $method, EntityInterface $parent = null): Response
48
    {
49
        $entityClass = $method->getReturnEntity();
50
        $result      = $this->send($method);
51
52
        return $this->createResponseFromData($result, $entityClass, $parent);
53
    }
54
55
    /**
56
     * Sends the request
57
     *
58
     * @param MethodInterface $methodInstance
59
     *
60
     * @return null|string
61
     */
62
    protected function send(MethodInterface $methodInstance): ?string
63
    {
64
        $options = [
65
            'query' => $methodInstance->getPropertiesArray(),
0 ignored issues
show
Bug introduced by
The method getPropertiesArray() does not exist on Teebot\Api\Method\MethodInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Teebot\Api\Method\MethodInterface. ( Ignorable by Annotation )

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

65
            'query' => $methodInstance->/** @scrutinizer ignore-call */ getPropertiesArray(),
Loading history...
66
        ];
67
68
        if ($methodInstance->hasAttachedData()) {
69
            $options = [
70
                'multipart' => $methodInstance->getPropertiesMultipart(),
0 ignored issues
show
Bug introduced by
The method getPropertiesMultipart() does not exist on Teebot\Api\Method\MethodInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Teebot\Api\Method\MethodInterface. ( Ignorable by Annotation )

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

70
                'multipart' => $methodInstance->/** @scrutinizer ignore-call */ getPropertiesMultipart(),
Loading history...
71
            ];
72
        }
73
74
        return $this->httpClient->request($methodInstance->getName(), $options);
75
    }
76
77
    /**
78
     * Creates the Response object from received data.
79
     *
80
     * @param string               $receivedData Received data from Telegram's servers
81
     * @param null|string          $entityClass  Entity class name that should be passed to Response constructor
82
     * @param null|EntityInterface $parent       Parent entity
83
     *
84
     * @return Response
85
     */
86
    public function createResponseFromData(
87
        string $receivedData,
88
        ?string $entityClass,
89
        EntityInterface $parent = null
90
    ): Response {
91
        return new Response($receivedData, $entityClass, $parent);
92
    }
93
}
94