Total Complexity | 7 |
Total Lines | 66 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
9 | abstract class Model |
||
10 | { |
||
11 | |||
12 | use Fillable; |
||
13 | |||
14 | use Request; |
||
|
|||
15 | |||
16 | /** |
||
17 | * @url https://core.telegram.org/bots/api#available-methods |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $method; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $required = []; |
||
26 | |||
27 | /** |
||
28 | * Fill with parameters |
||
29 | * |
||
30 | * @param array $data |
||
31 | * @return $this |
||
32 | */ |
||
33 | public function fill(array $data = []) |
||
34 | { |
||
35 | $this->fillData($data); |
||
36 | return $this; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Send action/request |
||
41 | * |
||
42 | * @return array |
||
43 | * @throws RequiredParameterException |
||
44 | */ |
||
45 | public function send() |
||
46 | { |
||
47 | $this->checkRequired(); |
||
48 | |||
49 | return $this->sendRequest( |
||
50 | $this->collectParameters() |
||
51 | ); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return array |
||
56 | */ |
||
57 | private function collectParameters() |
||
58 | { |
||
59 | $filtered = array_filter(get_object_vars($this)); |
||
60 | |||
61 | return array_diff_key($filtered, get_class_vars(self::class)); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @throws RequiredParameterException |
||
66 | */ |
||
67 | private function checkRequired() |
||
75 | } |
||
76 | |||
77 | } |
||
78 | |||
82 | } |