| Conditions | 29 | 
| Total Lines | 96 | 
| Lines | 0 | 
| Ratio | 0 % | 
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:
Complex classes like LinphoneCallbacks.call_state_changed_handle() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | #!/usr/bin/env python  | 
            ||
| 116 | def call_state_changed_handle(self, core, call, call_state, message):  | 
            ||
| 117 |         logger.debug("call_state_changed (%s - %s)", call_state, message) | 
            ||
| 118 | |||
| 119 | remote_uri = call.remote_address.as_string_uri_only()  | 
            ||
| 120 | |||
| 121 |         DoorPi().event_handler('OnCallStateChange', __name__, { | 
            ||
| 122 | 'remote_uri': remote_uri,  | 
            ||
| 123 | 'call_state': call_state,  | 
            ||
| 124 | 'state': message  | 
            ||
| 125 | })  | 
            ||
| 126 | |||
| 127 | if call_state == linphone.CallState.Idle:  | 
            ||
| 128 | pass  | 
            ||
| 129 | elif call_state == linphone.CallState.IncomingReceived:  | 
            ||
| 130 |             DoorPi().event_handler('BeforeCallIncoming', __name__, {'remote_uri': remote_uri}) | 
            ||
| 131 | if core.current_call and core.current_call.state > linphone.CallState.IncomingReceived:  | 
            ||
| 132 |                 logger.debug("Incoming call while another call is active") | 
            ||
| 133 |                 logger.debug("- incoming.remote_uri: %s", call) | 
            ||
| 134 |                 logger.debug("- current.remote_uri : %s", core.current_call) | 
            ||
| 135 | |||
| 136 | if core.current_call.remote_address.as_string_uri_only() == remote_uri:  | 
            ||
| 137 |                     logger.info("Current call is incoming call - quitting current and connecting to incoming. Maybe connection reset?") | 
            ||
| 138 |                     DoorPi().event_handler('OnCallReconnect', __name__, {'remote_uri': remote_uri}) | 
            ||
| 139 | core.terminate_call(core.current_call)  | 
            ||
| 140 | DoorPi().sipphone.reset_call_start_datetime()  | 
            ||
| 141 | core.accept_call_with_params(call, DoorPi().sipphone.base_config)  | 
            ||
| 142 |                     DoorPi().event_handler('AfterCallReconnect', __name__) | 
            ||
| 143 | return  | 
            ||
| 144 | else:  | 
            ||
| 145 | if self.is_admin_number(remote_uri):  | 
            ||
| 146 |                         logger.info("Incoming and current call are different - incoming is AdminNumber, so hanging up current call") | 
            ||
| 147 |                         DoorPi().event_handler('OnCallIncoming', __name__, {'remote_uri': remote_uri}) | 
            ||
| 148 | core.terminate_call(core.current_call)  | 
            ||
| 149 | DoorPi().sipphone.reset_call_start_datetime()  | 
            ||
| 150 | core.accept_call_with_params(call, DoorPi().sipphone.base_config)  | 
            ||
| 151 |                         DoorPi().event_handler('AfterCallIncoming', __name__, {'remote_uri': remote_uri}) | 
            ||
| 152 | return  | 
            ||
| 153 | else:  | 
            ||
| 154 |                         logger.info("Incoming and current call are different - sending busy signal to incoming call") | 
            ||
| 155 |                         DoorPi().event_handler('OnCallBusy', __name__, {'remote_uri': remote_uri}) | 
            ||
| 156 | core.decline_call(call, linphone.Reason.Busy)  | 
            ||
| 157 |                         DoorPi().event_handler('AfterCallBusy', __name__) | 
            ||
| 158 | return  | 
            ||
| 159 | if self.is_admin_number(remote_uri):  | 
            ||
| 160 |                 DoorPi().event_handler('OnCallIncoming', __name__, {'remote_uri': remote_uri}) | 
            ||
| 161 | DoorPi().sipphone.reset_call_start_datetime()  | 
            ||
| 162 | core.accept_call_with_params(call, DoorPi().sipphone.base_config)  | 
            ||
| 163 |                 DoorPi().event_handler('AfterCallIncoming', __name__, {'remote_uri': remote_uri}) | 
            ||
| 164 | return  | 
            ||
| 165 | else:  | 
            ||
| 166 |                 DoorPi().event_handler('OnCallReject', __name__) | 
            ||
| 167 | core.decline_call(call, linphone.Reason.Forbidden) #Declined  | 
            ||
| 168 |                 DoorPi().event_handler('AfterCallReject', __name__) | 
            ||
| 169 | return  | 
            ||
| 170 | elif call_state == linphone.CallState.OutgoingInit:  | 
            ||
| 171 | pass  | 
            ||
| 172 | elif call_state == linphone.CallState.OutgoingProgress:  | 
            ||
| 173 | pass  | 
            ||
| 174 | elif call_state == linphone.CallState.OutgoingRinging:  | 
            ||
| 175 | pass  | 
            ||
| 176 | elif call_state == linphone.CallState.OutgoingEarlyMedia:  | 
            ||
| 177 |             DoorPi().event_handler('OnCallMediaStateChange', __name__) | 
            ||
| 178 | elif call_state == linphone.CallState.Connected:  | 
            ||
| 179 |             DoorPi().event_handler('OnCallStateConnect', __name__) | 
            ||
| 180 | elif call_state == linphone.CallState.StreamsRunning:  | 
            ||
| 181 |             DoorPi().event_handler('AfterCallStateConnect', __name__) | 
            ||
| 182 |             DoorPi().event_handler('OnCallMediaStateChange', __name__) | 
            ||
| 183 | elif call_state == linphone.CallState.Pausing:  | 
            ||
| 184 | pass  | 
            ||
| 185 | elif call_state == linphone.CallState.Paused:  | 
            ||
| 186 |             DoorPi().event_handler('OnCallMediaStateChange', __name__) | 
            ||
| 187 | elif call_state == linphone.CallState.Resuming:  | 
            ||
| 188 |             DoorPi().event_handler('OnCallStateConnect', __name__) | 
            ||
| 189 |             DoorPi().event_handler('OnCallMediaStateChange', __name__) | 
            ||
| 190 | elif call_state == linphone.CallState.Refered:  | 
            ||
| 191 | pass  | 
            ||
| 192 | elif call_state == linphone.CallState.Error:  | 
            ||
| 193 |             if message == "Busy here": DoorPi().event_handler('OnCallStateDismissed', __name__) | 
            ||
| 194 | elif call_state == linphone.CallState.End:  | 
            ||
| 195 |             if message == "Call declined.": DoorPi().event_handler('OnCallStateReject', __name__) | 
            ||
| 196 |             DoorPi().event_handler('OnCallStateDisconnect', __name__) | 
            ||
| 197 | elif call_state == linphone.CallState.PausedByRemote:  | 
            ||
| 198 | pass  | 
            ||
| 199 | elif call_state == linphone.CallState.UpdatedByRemote:  | 
            ||
| 200 | pass  | 
            ||
| 201 | elif call_state == linphone.CallState.IncomingEarlyMedia:  | 
            ||
| 202 |             DoorPi().event_handler('OnCallMediaStateChange', __name__) | 
            ||
| 203 | elif call_state == linphone.CallState.Updating:  | 
            ||
| 204 |             DoorPi().event_handler('OnCallStateConnect', __name__) | 
            ||
| 205 |             DoorPi().event_handler('OnCallMediaStateChange', __name__) | 
            ||
| 206 | elif call_state == linphone.CallState.Released:  | 
            ||
| 207 | pass  | 
            ||
| 208 | elif call_state == linphone.CallState.EarlyUpdatedByRemote:  | 
            ||
| 209 | pass  | 
            ||
| 210 | elif call_state == linphone.CallState.EarlyUpdating:  | 
            ||
| 211 | pass  | 
            ||
| 212 | def notify_presence_received(self, core, linphone_friend): pass  | 
            ||
| 242 | __del__ = destroy  |