| Conditions | 8 |
| Total Lines | 52 |
| 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 | from django.apps import AppConfig |
||
| 26 | @register(Tags.database, Tags.compatibility) |
||
| 27 | def check_databases_compatibility(app_configs, **kwargs): |
||
| 28 | errors = [] |
||
| 29 | databases = settings.DATABASES |
||
| 30 | original_enabled_databases = getattr(settings, 'CACHALOT_DATABASES', |
||
| 31 | SUPPORTED_ONLY) |
||
| 32 | enabled_databases = cachalot_settings.CACHALOT_DATABASES |
||
| 33 | if original_enabled_databases == SUPPORTED_ONLY: |
||
| 34 | if not cachalot_settings.CACHALOT_DATABASES: |
||
| 35 | errors.append(Warning( |
||
| 36 | 'None of the configured databases are supported ' |
||
| 37 | 'by django-cachalot.', |
||
| 38 | hint='Use a supported database, or remove django-cachalot, or ' |
||
| 39 | 'put at least one database alias in `CACHALOT_DATABASES` ' |
||
| 40 | 'to force django-cachalot to use it.', |
||
| 41 | id='cachalot.W002' |
||
| 42 | )) |
||
| 43 | elif enabled_databases.__class__ in ITERABLES: |
||
| 44 | for db_alias in enabled_databases: |
||
| 45 | if db_alias in databases: |
||
| 46 | engine = databases[db_alias]['ENGINE'] |
||
| 47 | if engine not in SUPPORTED_DATABASE_ENGINES: |
||
| 48 | errors.append(Warning( |
||
| 49 | 'Database engine %r is not supported ' |
||
| 50 | 'by django-cachalot.' % engine, |
||
| 51 | hint='Switch to a supported database engine.', |
||
| 52 | id='cachalot.W003' |
||
| 53 | )) |
||
| 54 | else: |
||
| 55 | errors.append(Error( |
||
| 56 | 'Database alias %r from `CACHALOT_DATABASES` ' |
||
| 57 | 'is not defined in `DATABASES`.' % db_alias, |
||
| 58 | hint='Change `CACHALOT_DATABASES` to be compliant with' |
||
| 59 | '`CACHALOT_DATABASES`', |
||
| 60 | id='cachalot.E001', |
||
| 61 | )) |
||
| 62 | |||
| 63 | if not enabled_databases: |
||
| 64 | errors.append(Warning( |
||
| 65 | 'Django-cachalot is useless because no database ' |
||
| 66 | 'is configured in `CACHALOT_DATABASES`.', |
||
| 67 | hint='Reconfigure django-cachalot or remove it.', |
||
| 68 | id='cachalot.W004' |
||
| 69 | )) |
||
| 70 | else: |
||
| 71 | errors.append(Error( |
||
| 72 | "`CACHALOT_DATABASES` must be either %r or a list, tuple, " |
||
| 73 | "frozenset or set of database aliases." % SUPPORTED_ONLY, |
||
| 74 | hint='Remove `CACHALOT_DATABASES` or change it.', |
||
| 75 | id='cachalot.E002', |
||
| 76 | )) |
||
| 77 | return errors |
||
| 78 | |||
| 90 |