nephila/django-meta

View on GitHub

Showing 14 of 18 total issues

File views.py has 380 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
import warnings
from datetime import date

from django.apps import apps
Severity: Minor
Found in meta/views.py - About 5 hrs to fix

    MetadataMixin has 32 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class MetadataMixin(FullUrlMixin):
        """
        Django CBV mixin to prepare metadata for the view context
        """
    
    
    Severity: Minor
    Found in meta/views.py - About 4 hrs to fix

      Function schema has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def schema(self):
              """
              Schema.org object description.
      
              Items in the schema are converted in a format suitable of json encoding at this stage:
      Severity: Minor
      Found in meta/views.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 __init__ has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __init__(self, **kwargs):
              self.request = kwargs.get("request", None)
              self.use_sites = kwargs.get("use_sites", get_setting("USE_SITES"))
              self.title = kwargs.get("title")
              self.og_title = kwargs.get("og_title")
      Severity: Minor
      Found in meta/views.py - About 1 hr to fix

        Function towncrier_check has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        def towncrier_check(c):  # NOQA
            """Check towncrier files."""
            output = io.StringIO()
            c.run("git branch -a --contains HEAD", out_stream=output)
            skipped_branch_prefix = ["pull/", "release/", "develop", "master", "HEAD"]
        Severity: Minor
        Found in tasks.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 _get_meta_value has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def _get_meta_value(self, field, value):
                """
                Build metadata values from :py:attr:`_metadata`
        
                :param field: metadata field name
        Severity: Minor
        Found in meta/models.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 as_meta has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def as_meta(self, request=None):
                """
                Populates the :py:class:`~meta.views.Meta` object  with values from :py:attr:`_metadata`
        
                :param request: optional request object. Used to build the correct URI for linked objects
        Severity: Minor
        Found in meta/models.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 keywords has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def keywords(self, keywords):
                if keywords is None:
                    kws = get_setting("DEFAULT_KEYWORDS")
                else:
                    if not hasattr(keywords, "__iter__"):
        Severity: Minor
        Found in meta/views.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 meta_namespaces has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        def meta_namespaces(context):
            """
            Include OG namespaces. To be used in the <head> tag.
            """
            # do nothing if meta is not in context
        Severity: Minor
        Found in meta/templatetags/meta.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

        Function get_domain has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_domain(self):
                """
                Discover the current website domain
        
                :py:class:`django.contrib.sites.models.Site`
        Severity: Minor
        Found in meta/views.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

        Function image_object has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def image_object(self, image):
                try:
                    if image:
                        image["url"] = self._normalize_media_url(image.get("url", None))
                        if self.get_protocol() == "https":
        Severity: Minor
        Found in meta/views.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 item
        Severity: Major
        Found in meta/views.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                          return {itemkey: process_item(itemvalue) for itemkey, itemvalue in item.items()}
          Severity: Major
          Found in meta/views.py - About 30 mins to fix

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

                def _get_full_url(self, url):
                    """
                    Build the full URL (protocol and domain included) for the URL given as argument
            
                    :param url: absolute (domain-less) URL
            Severity: Minor
            Found in meta/views.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

            Severity
            Category
            Status
            Source
            Language