adsabs/biblib-service

View on GitHub
biblib/views/notes_view.py

Summary

Maintainability
F
3 days
Test Coverage

File notes_view.py has 345 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from biblib.utils import err, get_post_data
from biblib.models import Notes
from biblib.views.base_view import BaseView
from flask import request, current_app
from flask_discoverer import advertise
Severity: Minor
Found in biblib/views/notes_view.py - About 4 hrs to fix

    Function post has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def post(self, library, document_id):
            """
            HTTP POST request that adds a note to the library
            :param library: library ID
            :param document_id: bibcode
    Severity: Minor
    Found in biblib/views/notes_view.py - About 55 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 get has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def get(self, library,  document_id):
            """
            HTTP GET request that gets a note from the library
            :param library: library ID
            :param document_id: bibcode
    Severity: Minor
    Found in biblib/views/notes_view.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 put has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def put(self, library, document_id):
            """
            HTTP PUT request that updates a note of the library
            :param library: library ID
            :param document_id: bibcode
    Severity: Minor
    Found in biblib/views/notes_view.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 too many return statements within this function.
    Open

                return err(WRONG_TYPE_ERROR)
    Severity: Major
    Found in biblib/views/notes_view.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return err(MISSING_NOTE_ERROR)
      Severity: Major
      Found in biblib/views/notes_view.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                    return response, 201
        Severity: Major
        Found in biblib/views/notes_view.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return err(NO_PERMISSION_ERROR)
          Severity: Major
          Found in biblib/views/notes_view.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return response, 200 
            Severity: Major
            Found in biblib/views/notes_view.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return err(INVALID_CONTENT_ERROR)
              Severity: Major
              Found in biblib/views/notes_view.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return err(MISSING_NOTE_ERROR)
                Severity: Major
                Found in biblib/views/notes_view.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return response, 200
                  Severity: Major
                  Found in biblib/views/notes_view.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return err(MISSING_NOTE_ERROR)
                    Severity: Major
                    Found in biblib/views/notes_view.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return err(NO_PERMISSION_ERROR)
                      Severity: Major
                      Found in biblib/views/notes_view.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return err(NO_PERMISSION_ERROR)
                        Severity: Major
                        Found in biblib/views/notes_view.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                      return err(NO_PERMISSION_ERROR)
                          Severity: Major
                          Found in biblib/views/notes_view.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                    return response, 200 
                            Severity: Major
                            Found in biblib/views/notes_view.py - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                          return err(WRONG_TYPE_ERROR)
                              Severity: Major
                              Found in biblib/views/notes_view.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                        return {}, 200
                                Severity: Major
                                Found in biblib/views/notes_view.py - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                              return err(NO_PERMISSION_ERROR)
                                  Severity: Major
                                  Found in biblib/views/notes_view.py - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                                return err(INVALID_BIBCODE_ERROR)
                                    Severity: Major
                                    Found in biblib/views/notes_view.py - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                                  return err(DUPLICATE_NOTE_ERROR)
                                      Severity: Major
                                      Found in biblib/views/notes_view.py - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                    return current_app.logger.error('Error: {0}'
                                        Severity: Major
                                        Found in biblib/views/notes_view.py - About 30 mins to fix

                                          Function delete has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                          Open

                                              def delete(self, library, document_id):
                                                  """
                                                  HTTP DELETE request that deletes a note from the library
                                                  :param library: library ID
                                                  :param document_id: bibcode
                                          Severity: Minor
                                          Found in biblib/views/notes_view.py - About 25 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

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

                                                  try:
                                                      data = get_post_data(
                                                          request,
                                                          types=dict(params=dict, action=str)
                                                      )
                                          Severity: Major
                                          Found in biblib/views/notes_view.py and 1 other location - About 4 hrs to fix
                                          biblib/views/notes_view.py on lines 277..288

                                          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 75.

                                          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:
                                                      data = get_post_data(
                                                          request,
                                                          types=dict(params=dict, action=str)
                                                      )
                                          Severity: Major
                                          Found in biblib/views/notes_view.py and 1 other location - About 4 hrs to fix
                                          biblib/views/notes_view.py on lines 366..376

                                          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 75.

                                          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 3 locations. Consider refactoring.
                                          Open

                                                      note = session.query(Notes).filter(
                                                          Notes.bibcode == document_id,
                                                          Notes.library_id == library_id
                                          Severity: Major
                                          Found in biblib/views/notes_view.py and 2 other locations - About 1 hr to fix
                                          biblib/views/permission_view.py on lines 68..71
                                          biblib/views/permission_view.py on lines 87..90

                                          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 38.

                                          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

                                          There are no issues that match your filters.

                                          Category
                                          Status