Conditions | 25 |
Paths | 21 |
Total Lines | 67 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Tests | 30 |
CRAP Score | 37.0709 |
Changes | 4 | ||
Bugs | 0 | Features | 2 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
41 | 14 | public function __construct(array $data, $bot_name) |
|
42 | { |
||
43 | 14 | if (isset($data['ok'], $data['result'])) { |
|
44 | 12 | if (is_array($data['result'])) { |
|
45 | 11 | if ($data['ok'] && !$this->isAssoc($data['result']) && !isset($data['result'][0]['user'])) { |
|
46 | //Get Update |
||
47 | 2 | foreach ($data['result'] as $update) { |
|
48 | 2 | $this->result[] = new Update($update, $bot_name); |
|
49 | } |
||
50 | 9 | } elseif ($data['ok'] && !$this->isAssoc($data['result']) && isset($data['result'][0]['user'])) { |
|
51 | //Response from getChatAdministrators |
||
52 | $this->result = []; |
||
|
|||
53 | foreach ($data['result'] as $user) { |
||
54 | $this->result[] = new ChatMember($user); |
||
55 | } |
||
56 | 9 | } elseif ($data['ok'] && $this->isAssoc($data['result'])) { |
|
57 | 9 | if (isset($data['result']['total_count'])) { |
|
58 | //Response from getUserProfilePhotos |
||
59 | 1 | $this->result = new UserProfilePhotos($data['result']); |
|
60 | 8 | } elseif (isset($data['result']['file_id'])) { |
|
61 | //Response from getFile |
||
62 | 1 | $this->result = new File($data['result']); |
|
63 | 7 | } elseif (isset($data['result']['username'])) { |
|
64 | //Response from getMe |
||
65 | $this->result = new User($data['result']); |
||
66 | 7 | } elseif (isset($data['result']['id'])) { |
|
67 | //Response from getChat |
||
68 | $this->result = new Chat($data['result']); |
||
69 | 7 | } elseif (isset($data['result']['user'])) { |
|
70 | //Response from getChatMember |
||
71 | $this->result = new ChatMember($data['result']); |
||
72 | } else { |
||
73 | //Response from sendMessage |
||
74 | 7 | $this->result = new Message($data['result'], $bot_name); |
|
75 | } |
||
76 | } |
||
77 | |||
78 | 11 | $this->ok = $data['ok']; |
|
79 | 11 | $this->error_code = null; |
|
80 | 11 | $this->description = null; |
|
81 | } else { |
||
82 | 2 | if ($data['ok'] && $data['result'] === true) { |
|
83 | //Response from setWebhook set |
||
84 | 2 | $this->ok = $data['ok']; |
|
85 | 2 | $this->result = true; |
|
86 | 2 | $this->error_code = null; |
|
87 | 2 | $this->description = isset($data['description']) ? $data['description'] : ''; |
|
88 | } elseif (is_numeric($data['result'])) { |
||
89 | //Response from getChatMembersCount |
||
90 | $this->result = $data['result']; |
||
91 | } else { |
||
92 | $this->ok = false; |
||
93 | $this->result = null; |
||
94 | $this->error_code = $data['error_code']; |
||
95 | 12 | $this->description = $data['description']; |
|
96 | } |
||
97 | } |
||
98 | } else { |
||
99 | //webHook not set |
||
100 | 2 | $this->ok = false; |
|
101 | 2 | $this->result = isset($data['result']) ? $data['result'] : null; |
|
102 | 2 | $this->error_code = isset($data['error_code']) ? $data['error_code'] : null; |
|
103 | 2 | $this->description = isset($data['description']) ? $data['description'] : null; |
|
104 | |||
105 | //throw new TelegramException('ok(variable) is not set!'); |
||
1 ignored issue
–
show
|
|||
106 | } |
||
107 | 14 | } |
|
108 | |||
170 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..