adsabs/biblib-service

View on GitHub
biblib/views/library_view.py

Summary

Maintainability
D
2 days
Test Coverage

File library_view.py has 503 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Library view
"""

from biblib.views import USER_ID_KEYWORD
Severity: Major
Found in biblib/views/library_view.py - About 1 day to fix

    Function update_notes has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

        def update_notes(cls, session, library, updated_list):
            """
            Updates the notes based on the solr canonical bibcodes response
            :param session: necessary for all the queries 
            :param library: library to update
    Severity: Minor
    Found in biblib/views/library_view.py - About 3 hrs 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 solr_update_library has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def solr_update_library(cls, library_id, solr_docs, session):
            """
            Updates the library based on the solr canonical bibcodes response
            :param library: library_id of the library to update
            :param solr_docs: solr docs from the bigquery response
    Severity: Minor
    Found in biblib/views/library_view.py - About 1 hr 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 process_solr has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def process_solr(self, library, start, rows, sort, fl, session, add_sort):
            """
            Processes the request to solr big query
            :param library: <string> <library ID>
            :param start: <int> used to delimit the start of pagination 
    Severity: Minor
    Found in biblib/views/library_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 process_solr has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def process_solr(self, library, start, rows, sort, fl, session, add_sort):
    Severity: Major
    Found in biblib/views/library_view.py - About 50 mins to fix

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

          def get_library_data(self, data):
              """
              Processes the get request for the library and assembles a response
              :param data: <dict> containing user, service_uid, library_id, start, rows, sort, fl, 
                          raw_library, notes and session. 
      Severity: Minor
      Found in biblib/views/library_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 get has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def get(self, library):
              """
              HTTP GET request that returns all the documents inside a given
              user's library
              :param library: library slug
      Severity: Minor
      Found in biblib/views/library_view.py - About 35 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(NO_PERMISSION_ERROR)
      Severity: Major
      Found in biblib/views/library_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/library_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/library_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/library_view.py - About 30 mins to fix

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

                  def load_parameters(self, request): 
                      """
                      Loads parameters necessary for the Solr search
                      :param request: request object
              
              
              Severity: Minor
              Found in biblib/views/library_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

                  def has_read_access(self, service_uid, library):
                      """
                      Checks if the user has read access 
                      :param service_uid: user service id 
                      :param library: 
              Severity: Major
              Found in biblib/views/library_view.py and 1 other location - About 2 hrs to fix
              biblib/views/base_view.py on lines 704..719

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

              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

                              if note.id not in updated_ids: 
                                  updated_ids.add(note.id)
                                  updated_notes.append(note.as_dict())
              Severity: Major
              Found in biblib/views/library_view.py and 2 other locations - About 50 mins to fix
              biblib/views/library_view.py on lines 90..92
              biblib/views/library_view.py on lines 100..102

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

                                      if new_note.id not in updated_ids: 
                                          updated_ids.add(new_note.id)
                                          updated_notes.append(new_note.as_dict())
              Severity: Major
              Found in biblib/views/library_view.py and 2 other locations - About 50 mins to fix
              biblib/views/library_view.py on lines 77..79
              biblib/views/library_view.py on lines 100..102

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

                                  if canonical_note.id not in updated_ids: 
                                          updated_ids.add(canonical_note.id)
                                          updated_notes.append(canonical_note.as_dict())
              Severity: Major
              Found in biblib/views/library_view.py and 2 other locations - About 50 mins to fix
              biblib/views/library_view.py on lines 77..79
              biblib/views/library_view.py on lines 90..92

              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

              There are no issues that match your filters.

              Category
              Status