fossasia/open-event-orga-server

View on GitHub

Showing 1,194 of 1,194 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    for service in services:
        perm, _ = get_or_create(Permission, role=ownr, service=service)
        db.session.add(perm)
Severity: Minor
Found in populate_db.py and 1 other location - About 50 mins to fix
populate_db.py on lines 256..258

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 36.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        try:
            speaker_invite.status = 'accepted'
            save_to_db(speaker_invite, {'speaker invite accepetd'})
        except Exception:
            raise UnprocessableEntityError(
Severity: Minor
Found in app/api/speaker_invites.py and 1 other location - About 50 mins to fix
app/api/speaker_invites.py on lines 281..286

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 36.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function get_order_data has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def get_order_data(order):
    """Get order data from order object"""
    if not order:
        return {
            'Tax ID': '',
Severity: Minor
Found in app/api/helpers/csv_jobs_util.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function celery_task has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def celery_task(task_id):
    """
    Get CeleryTask status of an API based task
    """
    # in case of always eager, get results. don't call AsyncResult
Severity: Minor
Found in app/api/celery_tasks.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function health_check_celery has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def health_check_celery():
    """
    Check health status of celery and redis broker
    :return:
    """
Severity: Minor
Found in app/views/healthcheck.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid deeply nested control flow statements.
Open

                    if access_code:
                        access_code_value = access_code.code
                        break

Severity: Major
Found in app/api/helpers/csv_jobs_util.py - About 45 mins to fix

Function validate_date has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def validate_date(self, data, original_data):
        ends_at = data.get('valid_till', None)
        if 'id' in original_data['data']:
            try:
                discount_code = DiscountCode.query.filter_by(
Severity: Minor
Found in app/api/schema/discount_codes.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function send_email_task_smtp has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def send_email_task_smtp(payload):
    smtp_config = get_smtp_config()
    mailer_config = {'transport': {'use': 'smtp', **smtp_config}}

    mailer = Mailer(mailer_config)
Severity: Minor
Found in app/api/helpers/tasks.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function upload_to_gs has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

def upload_to_gs(bucket_name, client_id, client_secret, file, key, acl='public-read'):
Severity: Minor
Found in app/api/helpers/storage.py - About 45 mins to fix

Function virtual_check_in has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def virtual_check_in(event_identifier):
    """Search attendees by name or email."""
    event = db.session.query(Event).filter_by(identifier=event_identifier).first()
    if event is None:
        raise NotFoundError({'source': ''}, 'event can not be found')
Severity: Minor
Found in app/api/custom/events.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function db_drop_everything has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def db_drop_everything(db):
    # From http://www.sqlalchemy.org/trac/wiki/UsageRecipes/DropEverything

    conn = db.engine.connect()

Severity: Minor
Found in drop_db.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function create_permissions has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def create_permissions():
    ownr = Role.query.filter_by(name=Role.OWNER).first()
    orgr = Role.query.filter_by(name=Role.ORGANIZER).first()
    coorgr = Role.query.filter_by(name=Role.COORGANIZER).first()
    track_orgr = Role.query.filter_by(name=TRACK_ORGANIZER).first()
Severity: Minor
Found in populate_db.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid deeply nested control flow statements.
Open

                        if element not in relationships and data[element] != getattr(
                            order, element, None
                        ):
                            if element != 'status':
                                raise ForbiddenError(
Severity: Major
Found in app/api/orders.py - About 45 mins to fix

Function send_event_invoice has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def send_event_invoice(
    self, event_id: int, send_notification: bool = True, force: bool = False
):
    this_month = this_month_date()
    # Check if this month's invoice has been generated
Severity: Minor
Found in app/api/helpers/scheduled_jobs.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function send_email_to_attendees has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def send_email_to_attendees(order):
    attachments = None
    if current_app.config['ATTACH_ORDER_PDF']:
        attachments = [order.ticket_pdf_path, order.invoice_pdf_path]

Severity: Minor
Found in app/api/helpers/mail.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid deeply nested control flow statements.
Open

                        if session.ends_at is None or session.starts_at is None:
                            duration = ""
                        else:
                            duration = format_timedelta(
                                session.ends_at - session.starts_at
Severity: Major
Found in app/api/helpers/pentabarfxml.py - About 45 mins to fix

Function before_update_object has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def before_update_object(self, event_topic, data, view_kwargs):
        """
        method to save image urls before updating event object
        :param event_topic:
        :param data:
Severity: Minor
Found in app/api/event_topics.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function before_update_object has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def before_update_object(self, ticket, data, view_kwargs):
        """
        method to check if paid ticket has payment method before updating ticket object
        :param ticket:
        :param data:
Severity: Minor
Found in app/api/tickets.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid deeply nested control flow statements.
Open

                    if hasattr(data, f):
                        fetched = getattr(data, f)
                        break
            else:
Severity: Major
Found in app/api/helpers/permission_manager.py - About 45 mins to fix

Function query has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def query(self, view_kwargs):
        """
        query method for speakers list class
        :param view_kwargs:
        :return:
Severity: Minor
Found in app/api/speakers.py - About 45 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Severity
Category
Status
Source
Language