Passed
Push — draft ( 8ec7b9...aebf0a )
by Nikolay
03:09
created

SendLocationMethod::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 4
dl 0
loc 11
ccs 0
cts 8
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Greenplugin\TelegramBot\Method;
6
7
use Greenplugin\TelegramBot\Method\Traits\FillFromArrayTrait;
8
use Greenplugin\TelegramBot\Method\Traits\SendToChatVariablesTrait;
9
10
/**
11
 * Class SendLocationMethod.
12
 *
13
 * @see https://core.telegram.org/bots/api#sendlocation
14
 */
15
class SendLocationMethod
16
{
17
    use FillFromArrayTrait;
18
    use SendToChatVariablesTrait;
19
20
    /**
21
     * Latitude of the location.
22
     *
23
     * @var float
24
     */
25
    public $latitude;
26
27
    /**
28
     * Longitude of the location.
29
     *
30
     * @var float
31
     */
32
    public $longitude;
33
34
    /**
35
     * Period in seconds for which the location will be updated (see Live Locations, should be between 60 and 86400.
36
     *
37
     * @var int|null
38
     */
39
    public $livePeriod;
40
41
    /**
42
     * @param int|string $chatId
43
     * @param float      $latitude
44
     * @param float      $longitude
45
     * @param array|null $data
46
     *
47
     * @throws \Greenplugin\TelegramBot\Exception\BadArgumentException
48
     *
49
     * @return SendLocationMethod
50
     */
51
    public static function create($chatId, float $latitude, float $longitude, array $data = null): SendLocationMethod
52
    {
53
        $instance = new static();
54
        $instance->chatId = $chatId;
55
        $instance->latitude = $latitude;
56
        $instance->longitude = $longitude;
57
        if ($data) {
58
            $instance->fill($data);
59
        }
60
61
        return $instance;
62
    }
63
}
64