Conditions | 7 |
Total Lines | 52 |
Code Lines | 35 |
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:
1 | #!/usr/bin/env python3 |
||
13 | def check_configuration(client): |
||
14 | """ |
||
15 | Checking remote TYPO3 database configuration |
||
16 | :param client: String |
||
17 | :return: |
||
18 | """ |
||
19 | _path = system.config[client]['path'] |
||
20 | |||
21 | if 'LocalConfiguration' in _path: |
||
22 | stdout = mode.run_command( |
||
23 | helper.get_command(client, 'php') + ' -r "echo json_encode(include \'' + |
||
24 | system.config[client][ |
||
25 | 'path'] + '\');"', |
||
26 | client, |
||
27 | True |
||
28 | ) |
||
29 | |||
30 | _db_config = parse_database_credentials(json.loads(stdout)['DB']) |
||
31 | elif '.env' in _path: |
||
32 | # Try to parse settings from .env file |
||
33 | if 'db' not in system.config[client]: |
||
34 | system.config[client]['db'] = {} |
||
35 | |||
36 | _db_config = { |
||
37 | 'name': get_database_setting_from_env(client, system.config[client]['db'].get('name', 'TYPO3_CONF_VARS__DB__Connections__Default__dbname'), system.config[client]['path']), |
||
38 | 'host': get_database_setting_from_env(client, system.config[client]['db'].get('host', 'TYPO3_CONF_VARS__DB__Connections__Default__host'), system.config[client]['path']), |
||
39 | 'password': get_database_setting_from_env(client, system.config[client]['db'].get('password', 'TYPO3_CONF_VARS__DB__Connections__Default__password'), system.config[client]['path']), |
||
40 | 'port': get_database_setting_from_env(client, system.config[client]['db'].get('port', 'TYPO3_CONF_VARS__DB__Connections__Default__port'), system.config[client]['path']) |
||
41 | if get_database_setting_from_env(client, system.config[client]['db'].get('port', 'TYPO3_CONF_VARS__DB__Connections__Default__port'), system.config[client]['path']) != '' else 3306, |
||
42 | 'user': get_database_setting_from_env(client, system.config[client]['db'].get('user', 'TYPO3_CONF_VARS__DB__Connections__Default__user'), system.config[client]['path']), |
||
43 | } |
||
44 | elif 'AdditionalConfiguration.php' in _path: |
||
45 | # Try to parse settings from AdditionalConfiguration.php file |
||
46 | _db_config = { |
||
47 | 'name': get_database_setting_from_additional_configuration(client, 'dbname', system.config[client]['path']), |
||
48 | 'host': get_database_setting_from_additional_configuration(client, 'host', system.config[client]['path']), |
||
49 | 'password': get_database_setting_from_additional_configuration(client, 'password', system.config[client]['path']), |
||
50 | 'port': get_database_setting_from_additional_configuration(client, 'port', system.config[client]['path']) |
||
51 | if get_database_setting_from_additional_configuration(client, 'port', |
||
52 | system.config[client]['path']) != '' else 3306, |
||
53 | 'user': get_database_setting_from_additional_configuration(client, 'user', system.config[client]['path']), |
||
54 | } |
||
55 | else: |
||
56 | sys.exit( |
||
57 | output.message( |
||
58 | output.Subject.ERROR, |
||
59 | f'Can\'t extract database information from given path {system.config[client]["path"]}. Can only extract settings from the following files: LocalConfiguration.php, AdditionalConfiguration.php, .env', |
||
60 | False |
||
61 | ) |
||
62 | ) |
||
63 | |||
64 | system.config[client]['db'] = helper.clean_db_config(_db_config) |
||
65 | |||
110 | return helper.run_sed_command(client, f'"s/{name}=(.*).*$/\\1/p" {file}') |
||