| Conditions | 22 | 
| Total Lines | 94 | 
| Code Lines | 58 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 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 db_sync_tool.utility.parser.get_database_configuration() 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 python3 | ||
| 43 | def get_database_configuration(client): | ||
| 44 | """ | ||
| 45 | Getting database configuration of given client and defined sync base (framework type) | ||
| 46 | :param client: String | ||
| 47 | :return: | ||
| 48 | """ | ||
| 49 |     system.config['db'] = {} | ||
| 50 | |||
| 51 | # check framework type | ||
| 52 | _base = '' | ||
| 53 | |||
| 54 | automatic_type_detection() | ||
| 55 | |||
| 56 | if 'type' in system.config and ( | ||
| 57 | 'path' in system.config[mode.Client.ORIGIN] or | ||
| 58 | 'path' in system.config[mode.Client.TARGET] | ||
| 59 | ): | ||
| 60 | _type = system.config['type'].lower() | ||
| 61 | if _type == 'typo3': | ||
| 62 | # TYPO3 sync base | ||
| 63 | _base = Framework.TYPO3 | ||
| 64 | elif _type == 'symfony': | ||
| 65 | # Symfony sync base | ||
| 66 | _base = Framework.SYMFONY | ||
| 67 | elif _type == 'drupal': | ||
| 68 | # Drupal sync base | ||
| 69 | _base = Framework.DRUPAL | ||
| 70 | elif _type == 'wordpress': | ||
| 71 | # Wordpress sync base | ||
| 72 | _base = Framework.WORDPRESS | ||
| 73 | elif _type == 'laravel': | ||
| 74 | # Laravel sync base | ||
| 75 | _base = Framework.LARAVEL | ||
| 76 | else: | ||
| 77 | sys.exit( | ||
| 78 | output.message( | ||
| 79 | output.Subject.ERROR, | ||
| 80 |                     f'Framework type not supported: {_type}', | ||
| 81 | False | ||
| 82 | ) | ||
| 83 | ) | ||
| 84 | elif 'db' in system.config['origin'] or 'db' in system.config['target']: | ||
| 85 | _base = Framework.MANUAL | ||
| 86 | else: | ||
| 87 | sys.exit( | ||
| 88 | output.message( | ||
| 89 | output.Subject.ERROR, | ||
| 90 | f'Missing framework type or database credentials', | ||
| 91 | False | ||
| 92 | ) | ||
| 93 | ) | ||
| 94 | |||
| 95 |     sys.path.append('../recipes') | ||
| 96 | if _base == Framework.TYPO3: | ||
| 97 | # Import TYPO3 parser | ||
| 98 | from ..recipes import typo3 | ||
| 99 | _parser = typo3 | ||
| 100 | |||
| 101 | elif _base == Framework.SYMFONY: | ||
| 102 | # Import Symfony parser | ||
| 103 | from ..recipes import symfony | ||
| 104 | _parser = symfony | ||
| 105 | |||
| 106 | elif _base == Framework.DRUPAL: | ||
| 107 | # Import Symfony parser | ||
| 108 | from ..recipes import drupal | ||
| 109 | _parser = drupal | ||
| 110 | |||
| 111 | elif _base == Framework.WORDPRESS: | ||
| 112 | # Import Symfony parser | ||
| 113 | from ..recipes import wordpress | ||
| 114 | _parser = wordpress | ||
| 115 | |||
| 116 | elif _base == Framework.LARAVEL: | ||
| 117 | # Import Symfony parser | ||
| 118 | from ..recipes import laravel | ||
| 119 | _parser = laravel | ||
| 120 | |||
| 121 | if client == mode.Client.ORIGIN: | ||
| 122 | output.message( | ||
| 123 | output.Subject.INFO, | ||
| 124 | 'Sync base: ' + _base, | ||
| 125 | True | ||
| 126 | ) | ||
| 127 | |||
| 128 | if _base != Framework.MANUAL: | ||
| 129 | load_parser(client, _parser) | ||
| 130 | else: | ||
| 131 | if client == mode.Client.ORIGIN and mode.is_origin_remote(): | ||
| 132 | remote_client.load_ssh_client_origin() | ||
| 133 | elif client == mode.Client.TARGET and mode.is_target_remote(): | ||
| 134 | remote_client.load_ssh_client_target() | ||
| 135 | |||
| 136 | validate_database_credentials(client) | ||
| 137 | |||
| 240 |