| Conditions | 18 |
| Total Lines | 75 |
| Code Lines | 46 |
| 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 |
||
| 17 | def get_database_configuration(client): |
||
| 18 | """ |
||
| 19 | Getting database configuration of given client and defined sync base (framework type) |
||
| 20 | :param client: String |
||
| 21 | :return: |
||
| 22 | """ |
||
| 23 | system.config['db'] = {} |
||
| 24 | |||
| 25 | # check framework type |
||
| 26 | _base = '' |
||
| 27 | if 'type' in system.config: |
||
| 28 | _type = system.config['type'].lower() |
||
| 29 | if _type == 'typo3': |
||
| 30 | # TYPO3 sync base |
||
| 31 | _base = Framework.TYPO3 |
||
| 32 | elif _type == 'symfony': |
||
| 33 | # Symfony sync base |
||
| 34 | _base = Framework.SYMFONY |
||
| 35 | elif _type == 'drupal': |
||
| 36 | # Symfony sync base |
||
| 37 | _base = Framework.DRUPAL |
||
| 38 | elif _type == 'wordpress': |
||
| 39 | # Symfony sync base |
||
| 40 | _base = Framework.WORDPRESS |
||
| 41 | else: |
||
| 42 | sys.exit( |
||
| 43 | output.message( |
||
| 44 | output.Subject.ERROR, |
||
| 45 | f'Framework type not supported: {_type}', |
||
| 46 | False |
||
| 47 | ) |
||
| 48 | ) |
||
| 49 | elif 'db' in system.config['origin'] or 'db' in system.config['target']: |
||
| 50 | _base = Framework.MANUAL |
||
| 51 | else: |
||
| 52 | # Default is TYPO3 sync base |
||
| 53 | _base = Framework.TYPO3 |
||
| 54 | |||
| 55 | sys.path.append('../recipes') |
||
| 56 | if _base == Framework.TYPO3: |
||
| 57 | # Import TYPO3 parser |
||
| 58 | from ..recipes import typo3 |
||
| 59 | _parser = typo3 |
||
| 60 | |||
| 61 | elif _base == Framework.SYMFONY: |
||
| 62 | # Import Symfony parser |
||
| 63 | from ..recipes import symfony |
||
| 64 | _parser = symfony |
||
| 65 | |||
| 66 | elif _base == Framework.DRUPAL: |
||
| 67 | # Import Symfony parser |
||
| 68 | from ..recipes import drupal |
||
| 69 | _parser = drupal |
||
| 70 | |||
| 71 | elif _base == Framework.WORDPRESS: |
||
| 72 | # Import Symfony parser |
||
| 73 | from ..recipes import wordpress |
||
| 74 | _parser = wordpress |
||
| 75 | |||
| 76 | if client == mode.Client.ORIGIN: |
||
| 77 | output.message( |
||
| 78 | output.Subject.INFO, |
||
| 79 | 'Sync base: ' + _base, |
||
| 80 | True |
||
| 81 | ) |
||
| 82 | |||
| 83 | if _base != Framework.MANUAL: |
||
| 84 | load_parser(client, _parser) |
||
| 85 | else: |
||
| 86 | if client == mode.Client.ORIGIN and mode.is_origin_remote(): |
||
| 87 | remote_client.load_ssh_client_origin() |
||
| 88 | elif client == mode.Client.TARGET and mode.is_target_remote(): |
||
| 89 | remote_client.load_ssh_client_target() |
||
| 90 | |||
| 91 | validate_database_credentials(client) |
||
| 92 | |||
| 159 |