| Conditions | 23 |
| Total Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 0 | Features | 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 get() 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 |
||
| 8 | def get(*args, **kwargs): |
||
|
|
|||
| 9 | try: |
||
| 10 | if len(kwargs['name']) == 0: kwargs['name'] = [''] |
||
| 11 | if len(kwargs['value']) == 0: kwargs['value'] = [''] |
||
| 12 | |||
| 13 | sipphone = kwargs['DoorPiObject'].sipphone |
||
| 14 | |||
| 15 | status = {} |
||
| 16 | for name_requested in kwargs['name']: |
||
| 17 | status = {} |
||
| 18 | sipphone.thread_register('status_thread') |
||
| 19 | |||
| 20 | if name_requested in 'name': |
||
| 21 | status['name'] = sipphone.name |
||
| 22 | |||
| 23 | if name_requested in 'sound_codecs': |
||
| 24 | status['sound_codecs'] = sipphone.sound_codecs |
||
| 25 | if name_requested in 'sound_devices': |
||
| 26 | status['sound_devices'] = sipphone.sound_devices |
||
| 27 | |||
| 28 | if name_requested in 'sound_enable': |
||
| 29 | if len(sipphone.sound_codecs) and len(sipphone.sound_devices): |
||
| 30 | status['sound_enable'] = True |
||
| 31 | else: |
||
| 32 | status['sound_enable'] = False |
||
| 33 | |||
| 34 | if name_requested in 'video_codecs': |
||
| 35 | status['video_codecs'] = sipphone.video_codecs |
||
| 36 | if name_requested in 'video_devices': |
||
| 37 | status['video_devices'] = sipphone.video_devices |
||
| 38 | |||
| 39 | if name_requested in 'video_enable': |
||
| 40 | if len(sipphone.video_codecs) and len(sipphone.video_devices): |
||
| 41 | status['video_enable'] = True |
||
| 42 | else: |
||
| 43 | status['video_enable'] = False |
||
| 44 | |||
| 45 | if name_requested in 'recorder': |
||
| 46 | status['has_recorder'] = True if sipphone.recorder else False |
||
| 47 | if status['has_recorder']: |
||
| 48 | status['recorder_filename'] = sipphone.recorder.record_filename |
||
| 49 | status['recorder_parsed_filename'] = sipphone.recorder.parsed_record_filename |
||
| 50 | |||
| 51 | if name_requested in 'player': |
||
| 52 | status['has_player'] = True if sipphone.player else False |
||
| 53 | if status['has_player']: |
||
| 54 | status['player_filename'] = sipphone.player.player_filename |
||
| 55 | |||
| 56 | if name_requested in 'current_call': |
||
| 57 | status['current_call'] = sipphone.current_call_dump |
||
| 58 | |||
| 59 | return status |
||
| 60 | except Exception as exp: |
||
| 61 | logger.exception(exp) |
||
| 62 | return {'Error': 'could not create '+str(__name__)+' object - '+str(exp)} |
||
| 63 | |||
| 66 |