Completed
Push — master ( 1563e2...9d8e98 )
by Marcel
09:03
created

HttpDriver::typesAndWaits()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace BotMan\BotMan\Drivers;
4
5
use Illuminate\Support\Collection;
6
use BotMan\BotMan\Interfaces\HttpInterface;
7
use BotMan\BotMan\Interfaces\DriverInterface;
8
use Symfony\Component\HttpFoundation\Request;
9
use BotMan\BotMan\Messages\Incoming\IncomingMessage;
10
11
abstract class HttpDriver implements DriverInterface
12
{
13
    /** @var Collection|ParameterBag */
14
    protected $payload;
15
16
    /** @var Collection */
17
    protected $event;
18
19
    /** @var HttpInterface */
20
    protected $http;
21
22
    /** @var Collection */
23
    protected $config;
24
25
    /** @var string */
26
    protected $content;
27
28
    /**
29
     * Driver constructor.
30
     * @param Request $request
31
     * @param array $config
32
     * @param HttpInterface $http
33
     */
34
    final public function __construct(Request $request, array $config, HttpInterface $http)
35
    {
36
        $this->http = $http;
37
        $this->config = Collection::make($config);
38
        $this->content = $request->getContent();
0 ignored issues
show
Documentation Bug introduced by
It seems like $request->getContent() can also be of type resource. However, the property $content is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
39
        $this->buildPayload($request);
40
    }
41
42
    /**
43
     * Return the driver name.
44
     *
45
     * @return string
46
     */
47
    public function getName()
48
    {
49
        return static::DRIVER_NAME;
50
    }
51
52
    /**
53
     * Return the driver configuration.
54
     *
55
     * @return Collection
56
     */
57
    public function getConfig()
58
    {
59
        return $this->config;
60
    }
61
62
    /**
63
     * Return the raw request content.
64
     *
65
     * @return string
66
     */
67
    public function getContent()
68
    {
69
        return $this->content;
70
    }
71
72
    /**
73
     * @param IncomingMessage $matchingMessage
74
     * @return void
75
     */
76
    public function types(IncomingMessage $matchingMessage)
77
    {
78
        // Do nothing
79
    }
80
81
    /**
82
     * Send a typing indicator and wait for the given amount of seconds.
83
     * @param IncomingMessage $matchingMessage
84
     * @param int $seconds
85
     * @return mixed
86
     */
87
    public function typesAndWaits(IncomingMessage $matchingMessage, int $seconds)
88
    {
89
        $this->types($matchingMessage);
90
        sleep($seconds);
91
    }
92
93
    /**
94
     * @return bool
95
     */
96
    public function hasMatchingEvent()
97
    {
98
        return false;
99
    }
100
101
    /**
102
     * @param Request $request
103
     * @return void
104
     */
105
    abstract public function buildPayload(Request $request);
106
107
    /**
108
     * Low-level method to perform driver specific API requests.
109
     *
110
     * @param string $endpoint
111
     * @param array $parameters
112
     * @param \BotMan\BotMan\Messages\Incoming\IncomingMessage $matchingMessage
113
     * @return void
114
     */
115
    abstract public function sendRequest($endpoint, array $parameters, IncomingMessage $matchingMessage);
116
117
    /**
118
     * Tells if the stored conversation callbacks are serialized.
119
     *
120
     * @return bool
121
     */
122
    public function serializesCallbacks()
123
    {
124
        return true;
125
    }
126
}
127