Completed
Pull Request — master (#48)
by Rick
03:30
created

UnsuccessfulRequest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 40
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A mapSubObjects() 0 10 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace unreal4u\TelegramAPI\Telegram\Types\Custom;
5
6
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
7
use unreal4u\TelegramAPI\Telegram\Types\ResponseParameters;
8
9
/**
10
 * Not being used by the package itself, but useful for some bots to initialize if no response is actually expected
11
 */
12
class UnsuccessfulRequest extends TelegramTypes
13
{
14
    /**
15
     * Per definition, this will always be false, as this is an unsuccessful request
16
     * @var bool
17
     */
18
    public $ok = false;
19
20
    /**
21
     * An Integer ‘error_code’ field is returned, but its contents are subject to change in the future
22
     * @var int
23
     */
24
    public $error_code = 0;
25
26
    /**
27
     * In case of an unsuccessful request, ‘ok’ equals false and the error is explained in the ‘description’
28
     * @var string
29
     */
30
    public $description = '';
31
32
    /**
33
     * Some errors may also have an optional field ‘parameters’ of the type ResponseParameters, which can help to
34
     * automatically handle the error
35
     *
36
     * @see ResponseParameters
37
     * @var ResponseParameters
38
     */
39
    public $parameters = null;
40
41
    protected function mapSubObjects(string $key, array $data): TelegramTypes
42
    {
43
        switch ($key) {
44
            case 'parameters':
45
                return new ResponseParameters($data, $this->logger);
46
        }
47
48
        // Return always null if none of the objects above matches
49
        return parent::mapSubObjects($key, $data);
50
    }
51
}
52